Doubly-virtualized texture memory

ABSTRACT

A graphics system in which the dedicated graphics memory is doubly virtualized: it can be paged into host physical memory, and also, beyond that, into host bulk storage. Portions of host physical memory which are needed to support the graphics memory management process can be locked down.

This application claims the benefit of provisional applications No.60/143,655, filed Jul. 13, 1999, 60/138,248, filed Jun. 9, 1999 and60/138,350, filed Jun. 9, 1999.

BACKGROUND AND SUMMARY OF THE INVENTION

The present application relates to computer graphics rendering systemsand methods, and particularly to handling of texture data used byrendering accelerators for 3D graphics.

Background: 3D Computer Graphics

One of the driving features in the performance of most single-usercomputers is computer graphics. This is particularly important incomputer games and workstations, but is generally very important acrossthe personal computer market.

For some years the most critical area of graphics development has beenin three-dimensional (“3D”) graphics. The peculiar demands of 3Dgraphics are driven by the need to present a realistic view, on acomputer monitor, of a three-dimensional scene. The pattern written ontothe two-dimensional screen must therefore be derived from thethree-dimensional geometries in such a way that the user can easily“see” the three-dimensional scene (as if the screen were merely a windowinto a real three-dimensional scene). This requires extensivecomputation to obtain the correct image for display, taking account ofsurface textures, lighting, shadowing, and other characteristics.

The starting point (for the aspects of computer graphics considered inthe present application) is a three-dimensional scene, with specifiedviewpoint and lighting (etc.). The elements of a 3D scene are normallydefined by sets of polygons (typically triangles), each havingattributes such as color, reflectivity, and spatial location. (Forexample, a walking human, at a given instant, might be translated into afew hundred triangles which map out the surface of the human's body.)Textures are “applied” onto the polygons, to provide detail in thescene. (For example, a flat carpeted floor will look far more realisticif a simple repeating texture pattern is applied onto it.) Designers usespecialized modelling software tools, such as 3D Studio, to buildtextured polygonal models.

The 3D graphics pipeline consists of two major stages, or subsystems,referred to as geometry and rendering. The geometry stage is responsiblefor managing all polygon activities and for converting three-dimensionalspatial data into a two-dimensional representation of the viewed scene,with properly-transformed polygons. The polygons in thethree-dimensional scene, with their applied textures, must then betransformed to obtain their correct appearance from the viewpoint of themoment; this transformation requires calculation of lighting (andapparent brightness), foreshortening, obstruction, etc.

However, even after these transformations and extensive calculationshave been done, there is still a large amount of data manipulation to bedone: the correct values for EACH PIXEL of the transformed polygons mustbe derived from the two-dimensional representation. (This requires notonly interpolation of pixel values within a polygon, but also correctapplication of properly oriented texture maps.) The rendering stage isresponsible for these activities: it “renders” the two-dimensional datafrom the geometry stage to produce correct values for all pixels of eachframe of the image sequence.

The most challenging 3D graphics applications are dynamic rather thanstatic. In addition to changing objects in the scene, many applicationsalso seek to convey an illusion of movement by changing the scene inresponse to the user's input. Whenever a change in the orientation orposition of the camera is desired, every object in a scene must berecalculated relative to the new view. As can be imagined, a fast-pacedgame needing to maintain a high frame rate will require manycalculations and many memory accesses.

FIG. 2 shows a high-level overview of the processes performed in theoverall 3D graphics pipeline. However, this is a very general overview,which ignores the crucial issues is of what hardware performs whichoperations.

Texturing

There are different ways to add complexity to a 3D scene. Creating moreand more detailed models, consisting of a greater number of polygons, isone way to add visual interest to a scene. However, adding polygonsnecessitates paying the price of having to manipulate more geometry. 3Dsystems have what is known as a “polygon budget,” an approximate numberof polygons that can be manipulated without unacceptable performancedegradation. In general, fewer polygons yield higher frame rates.

The visual appeal of computer graphics rendering is greatly enhanced bythe use of “textures.” A texture is a two-dimensional image which ismapped into the data to be rendered. Textures provide a very efficientway to generate the level of minor surface detail which makes syntheticimages realistic, without requiring transfer of immense amounts of data.Texture patterns provide realistic detail at the sub-polygon level, sothe higher-level tasks of polygon-processing are not overloaded. SeeFoley et al., Computer Graphics: Principles and Practice (2.ed. 1990,corr.1995), especially at pages 741-744; Paul S. Heckbert, “Fundamentalsof Texture Mapping and Image Warping,” Thesis submitted to Dept. of EEand Computer Science, University of California, Berkeley, Jun. 17, 1994;Heckbert, “Survey of Computer Graphics,” IEEE Computer Graphics,November 1986, pp.56; all of which are hereby incorporated by reference.Game programmers have also found that texture mapping is generally avery efficient way to achieve very dynamic images without requiring ahugely increased memory bandwidth for data handling.

A typical graphics system reads data from a texture map, processes it,and writes color data to display memory. The processing may includemipmap filtering which requires access to several maps. The texture mapneed not be limited to colors, but can hold other information that canbe applied to a surface to affect its appearance; this could includeheight perturbation to give the effect of roughness. The individualelements of a texture map are called “texels. ”

Awkward side-effects of texture mapping occur unless the renderer canapply texture maps with correct perspective. Perspective-correctedtexture mapping involves an algorithm that translates “texels” (pixelsfrom the bitmap texture image) into display pixels in accordance withthe spatial orientation of the surface. Since the surfaces aretransformed (by the host or geometry engine) to produce a 2D view, thetextures will need to be similarly transformed by a linear transform(normally projective or “affine”). (In conventional terminology, thecoordinates of the object surface, i.e. the primitive being rendered,are referred to as an (s,t) coordinate space, and the map of the storedtexture is referred to a (u,v) coordinate space.) The transformation inthe resulting mapping means that a horizontal line in the (x,y) displayspace is very likely to correspond to a slanted line in the (u,v) spaceof the texture map, and hence many additional reads will occur, due tothe texturing operation, as rendering walks along a horizontal line ofpixels.

Data and Memory Management

Due to the extremely high data rates required at the end of therendering pipeline, many features of computer architecture take on newcomplexities in the context of computer graphics (and especially in thearea of texture management).

Virtual Memory Management

One of the basic tools of computer architecture is “virtual” memory.This is a technique which allows application software to use a verylarge range of memory addresses, without knowing how much physicalmemory is actually present on the computer, nor how the virtualaddresses correspond to the physical addresses which are actually usedto address the physical memory chips (or other memory devices) over abus.

Some further discussion of Virtual memory management can be found inHennessy & Patterson, Computer Architecture: a Quantititive Approach(2.ed.1996); Hwang and Briggs, Computer Architecture and ParallelProcessing (1984); Subieta, Object-based virtual memory for PCs (1990);Carr, Virtual memory management (1984); Lau, Performance improvement ofvirtual memory systems (1982); and Loshin, Efficient Memory Programming(1998); all of which are hereby incorporated by reference. An excellenthypertext tutorial is found in the Web pages which start athttp://cne.gmu.edu/Modules/VM/, and this hypertext tutorial is alsohereby incorporated by reference. Another useful online resource isfound at http://www.harlequin.com/mm/reference/faq.html, and this too ishereby incorporated by reference. Much current work can be found in theannual proceedings of the ACM International Symposium on MemoryManagement (ISMM), which are all hereby incorporated by reference.

AGP and GART

Beginning with the Pentium II▪, some Intel processors have included thecapability for an Accelerated Graphics Port (AGP). The AGP provides ahigh-speed dedicated bus for fast transfer of graphics data. (Unlike thePCI bus, the AGP bus is pipelined, and allows is only two devices onit.)

To support this high-speed bus, the Intel specification also provides aspecial protocol for “AGP memory.” This is not physically separatememory, but just dynamically-allocated system DRAM areas which thegraphics chip can access quickly. The Intel chip set includes addresstranslation hardware which makes the “AGP memory” look continuous to thegraphics controller. This permits the graphics chip to access largetexture bitmaps (e.g. 128 KB) as a single entity.

Intel's built-in chip set hardware is called the GART (Graphics AddressRemapping Table). The GART hardware is somewhat similar in function tothe paging hardware in the CPU chip, in that the processor “linear”virtual addresses get automatically translated into physical addresses(which may point to system RAM and local Frame Buffer memory, as well asthe AGP RAM).

However, this translation is fairly inflexible, and completely out ofthe user's control. Thus it cannot be optimized for particularapplications, software architectures, or graphic acceleratorarchitectures.

Virtual Texture Memory

Virtualization of texture memory, like virtualization of host memory,gives the user the impression of a memory space which is larger than canbe physically accommodated in real memory. This is achieved bypartitioning the memory space into a small physical working set and alarge virtual set with dynamic swapping between the two. For virtualmemory management in CPUs the physical working set is main memory andthe virtual set is disk storage.

The swapping required for virtual memory management is normally doneautomatically (as far as the application software is concerned). Thereis a vast amount of literature concerning CPU based virtual memorysystems and their management.

The apparently-larger virtual texture memory space increases performanceas the optimum set of textures (or part of textures) are chosen forresidence by the hardware. It also simplifies the management of texturememory by the driver and/or application where either or both try tomanage the memory manually. This is akin to program overlays before thedays of virtual memory on CPUs where the program had to dynamically loadand unload segments of itself.

The present inventor has realized that managing the texture memory inthe driver or by the application is very difficult (or impossible) to doproperly, because:

1. What does the driver/application do when it runs out of memory andneeds to fit another texture in? Which texture(s) does it delete?

2. The texture has to be completely resident and physically contiguousso a large enough space must be made available.

3. A texture which is about to be used MUST NOT be deleted or moved:otherwise all command buffers will be outdated.

4. In some cases a texture map will not fit into memory even when allother textures are deleted (a 2K×2K 32bpp texture map takes 16 MBytes ofmemory).

5. The texture heap must be compacted to reclaim storage.

The idea of applying virtual management techniques to textures in 3Dgraphics hardware appears to be suggested, for example, by U.S. Pat. No.5,790,130 to Gannett. This patent suggests that “A graphics hardwaredevice, coupled to the host computer, renders texture mapped images, andincludes a local memory that stores at least a portion of the texturedata stored in the system memory at any one time. A software daemon runson the processor of the host computer and manages transferring texturedata from the system memory to the local memory when needed by thehardware device to render an image.” (Abstract) This and/or othervirtual texture memory schemes are believed to have been used in someproducts of HP and SGI. However, the present inventor has realized thatthese schemes are ill-suited for most personal computer applications(and many workstation applications). The main aim in theseimplementation seems to have been to allow very large texture maps(16M×16M or larger) to be used. By contrast, the innovations in thepresent application are not motivated only by desire for such largemaps, but to remove the software problems in managing the comparativelysmall amount of texture storage (vs the large amounts of texture storagein SGI and HP machines) efficiently. Thus it is possible that thearchitectural innovations disclosed herein can be used in combinationwith those used by SGI and HP.

Doubly-Virtualized Texture Memory

As noted above, virtual memory architectures have long been used ingeneral-purpose computers. However, there turn out to be some surprisingdifficulties in using this idea in computer graphics (especially fortexture memory). The present application discloses several innovationsrelated to virtualization and caching of texture memory.

The present application claims the use of a two- or three-level memoryhierarchy for texture memory. In a sample implementation of thisarchitecture, the first level is the on-card memory—i.e. the privatememory attached to the rasterizer chip. (The “zeroth” level in thememory hierarchy is the on-chip cache, which is not particularlyinvolved with the virtual memory system.) The second level is the hostphysical memory, and the third level is the host's disks (or hostvirtual memory).

The normal scheme is for the page fault to cause the texture to beloaded from the host's physical memory, but it is possible to tag thenon-resident pages with a ‘virtual host texture’ bit which will cause aninterrupt. The host will service this interrupt and retrieve the texturepage off disk (either explicitly or via the host OS virtual memorysystem), lock it down and then have the hardware fetch it. Each graphicsprocess can have up to 256 MBytes of virtual textures so, in theory,would require up to 256 MB of host memory to be locked down (therebyremoving this memory from the general memory pool). Personal computerswith enough memory to reserve 256 MB for a texture backing store arestill rare, but by using the 3rd level of storage slower memory (i.e.disk) can be substituted for capacity.

Note that the disclosed memory hierarchy has AT LEAST three levels,typically four or more:

(possibly on-chip cache, and:)

on-card,

host physical, and

host bulk storage.

Preferably the graphics memory controller is able to lock down at leasta portion of the host memory space, as described in the detaileddescription. If the hardware is going to auto fetch pages from host, atleast some host memory must be locked down so it won't be paged in andout. This is implies that the graphics subsystem is denying the mainsystem access to some of its resources! This is a surprising choice,which is very unfriendly toward general system resources. Therefore, toavoid tying up host space with unneeded lockdowns, the presentlypreferred embodiment allows lockdown of only half the memory less 24M.

In the presently preferred embodiment, the memory hierarchy isimplemented with:

2KB on chip;

8-20M on card;

host physical memory of e.g. 20-200M; and

host bulk storage, typically many gigabytes.

Notable (and separately innovative) features of the virtual texturemapping architecture described in the present application include atleast the following: A single chip solution is provided; Two or threelevels of texture memory hierarchy are supported; The page faulting isall done in hardware with no host intervention; The texture memorymanagement function can be used to manage texture storage in the hostmemory in addition to the texture storage in our normal texture memory;Multiple memory pools are supported; and multiple rasterizers can besupported capably.

BRIEF DESCRIPTION OF THE DRAWING

The disclosed inventions will be described with reference to theaccompanying drawings, which show important sample embodiments of theinvention and which are incorporated in the specification hereof byreference, wherein:

FIG. 1 is an overview of a computer system, with a rendering subsystem,which incorporates the disclosed graphics memory management ideas.

FIG. 2 is a very high-level view of other processes performed in a 3Dgraphics computer system.

FIG. 3 shows a block diagram of a 3D graphics accelerator subsystem.

FIGS. 4A and 4B are a pair of flow charts which show how a texture isloaded, depending on whether a cache miss occurs.

FIG. 5 shows a 2-D coordinate space mapped to a 1-D address range.

FIG. 6 shows a 2×2 patch arrangement within a texture map.

FIGS. 7A and 7B show layouts in memory for the various supportedformats.

FIG. 8 shows how the map level and address can be encoded into the leastamount of bits.

FIG. 9 shows which texels the memory reads bring in and thecorresponding output fragments they will satisfy.

FIG. 10 shows a block diagram of the Texture Read Unit.

FIG. 11 shows a block diagram of the Primary Cache Manager.

FIG. 12 shows a block diagram of the Cache Directory.

FIG. 13 shows a block diagram of the CAM Cell.

FIG. 14 shows a block diagram of the Translation Look aside Buffer(TLB).

FIG. 15 shows a block diagram of an individual CAM cell.

FIG. 16 shows a sample configuration where two rasterizers are served bya common memory manager and bus interface chip.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

The numerous innovative teachings of the present application will bedescribed with particular reference to the presently preferredembodiment (by way of example, and not of limitation).

The following pages give details of a sample embodiment of the preferredrendering accelerator chip (referred to as “P3” in the followingdocument, although not all details may apply to every chip revisionmarketed as P3). Particular attention will be paid to the Texture ReadUnit of this chip, where many of the disclosed inventions areimplemented. Commonly-owned U.S. applications Ser. Nos. 09/322,828,09/280,250, and 09/266,052 provide various other details of the contextswithin which the claimed inventions are most preferably implemented, andare all incorporated herein by reference. The present application is oneof nine applications filed simultaneously, which are all contemplated tobe implemented together in a common system. The other applications areSer. Nos. 09/591,225 through 09/591,231, 09/591,532 and 09/591,533, andall are hereby incorporated by reference. Also incorporated by referenceare commonly owned co-pending U.S. provisional priority applications60/138,350 and 60/138,248, both filed Jun. 9, 1999, and provisionalapplications 60/143,826, 60/143,712, 60/143,661, 60/143,655, 60/143,822,60/143,825, 60/143,654, 60/143,660, 60/143,650, all filed on Jul. 13,1999.

The preferred embodiments presented are implemented in a PERMEDIA 3™(P3) graphics core produced by 3D Labs, Inc. The overall architecture ofthe graphics core is best viewed using the software paradigm of amessage passing system. In this system all the processing units areconnected in a long pipeline with communication with the adjacent unitsbeing done through message passing. Between each unit there is a smallamount of buffering, the size being specific to the local communicationsrequirements and speed of the two units. The message rate is variableand depends on the rendering mode. The messages do not propagate throughthe system at a fixed rate typical of a more traditional pipelinesystem. If the receiving block cannot accept a message, because itsinput buffer is full, then the sending block stalls until space isavailable. A more expensive version of this chip is also contemplated,and will be referred to as “RX” in the following description; the RX hasthe same functionality as the P3 chip, but has more memory etc. Bothchips, and other members of the 3Dlabs family of pipelined renderingaccelerators, may also be referred to generically as “GLINT” chips.

FIG. 1 shows a block diagram of a sample computer system context;however, the disclosed techniques can advantageously be incorporated inany number of graphics systems.

FIG. 3 shows a block diagram of a graphics processor which canincorporate the disclosed embodiments of the read-modify-write solutionsin its rendering subsystem. A sample board incorporating the P3™graphics processor may include these elements:

the P3™ graphics core itself;

a PCI/AGP interface;

DMA controllers for PCI/AGP interface to the graphics core and memory;

SGRAM/SDRAM, to which the chip has read-write access through its framebuffer (FB) and local buffer (LB) ports;

a RAMDAC, which provides analog color values in accordance with thecolor values read out from the SGRAM/SDRAM; and

a video stream interface for output and display connectivity.

Various claimed features, and/or features of particular interest, arefound in the Texture Read Unit, which will now be described in detail.

Texture Read Unit Description

The Texture Read Unit's main job is to manage the primary texture cache(the data part is in the Texture Filter Unit) and load texel data intoit, preferably in advance of when it is needed. The primary cache can beused as one large cache or as two smaller (half size) caches dependingon the type of texture mapping being done. The single large cache is anoptimization and allows higher cache hits when the texture map is largeor the polygon is large and a single bilinear texture is used.

When texture needs to be loaded the address(es) are calculated for thetexel data. These addresses may be physical addresses in which case theaddress is issued to the Memory Controller and some time later the datareturned. Alternatively the address may be a logical one so thefollowing steps are taken to resolve (or translate) it:

The logical address (really just the page part) is looked up in theTranslation Look aside Buffer (TLB) and if present the correspondingphysical address is issued to the Memory Controller.

The address translation may fail in the TLB so the page table in memoryis accessed and if the page is resident the physical address is lookedup, the TLB updated and the physical address is issued to the MemoryController.

The page may not be resident in the working set so the page is read fromhost memory (or the host asked for it via an interrupt) and when it hasbeen loaded the newly updated page table is read, the TLB updated andthe physical address is issued to the Memory Controller. The page may bemarked as a host texture in which case the address mapping is done, butthe texture is not downloaded.

The unit is controlled by the TextureReadMode0 and TextureReadMode1messages for texture 0 and texture 1 respectively. Both messages have anidentical format, however some modes are mutually exclusive as there arenot enough resources to allow all combinations. The supportedcombinations are:

One nearest or linear filtered texture using both'halves of the cache toachieve higher cache hit rates on larger texture maps or polygons.

Any two independent nearest or linear filtered textures, one per half ofthe cache.

One automatically (or per pixel) mip mapped texture (always texture 0)using both halves of the cache to store alternate levels of the mip map.

One 3D texture map using both halves of the cache to store alternateslices of the 3D volume.

Two independent mip mapped textures where the minification filters onlyuse texels from one level at a time (i.e. the filter areNearestMipNearest or LinearMipNearest). Each texture uses half thecache.

There are no interlocks to prevent the user selecting a non-supportedcombination and in this case the mode settings in TextureReadMode0 takepriority.

Performance

When the unit is disabled the active steps should take one cycle asshould all other messages irrespective of the enabled state of the unit.

When the unit is enabled the target throughput is one active stepmessage every 1 cycles for all mode combinations providing all requiredtexels are in the primary cache. The first cache miss in each bankrequiring a physical memory read or logical memory read with a TLB hitadds zero cycles but subsequent ones can take an extra cycle each. (Thenth cache miss for a step may be satisfied by an earlier cache load onthe same step so does not count for extra time.) The zero extra cyclescase can not be sustained as the actual address generation and readingwill take two cycles, however the flow of fragments into the M FIFOshould not be disrupted until the AG FIFOs blocks.

If there is a TLB miss, a page miss (i.e. not resident) or the cache isloaded from memory then the memory access time should be the limitingfactor.

The presence of other messages ignored by this unit but mixed in withthe active step messages should not cause any stalls in the pipelinewith a consequence loss of performance while the pipeline empties andfills up again.

The presence of messages which load up registers (mode or address, forexample) in this unit can wait for the unit to become idle as these areglobal and shared by all sub units (which may be operating on queuedwork).

Texture Memory Layouts

The Layout field in the TextureMapWidth registers selects how thetexture data is to be laid out in memory for each mip map level. Theoptions are:

Linear. Here the rows are stored one after another in memory. This istypically used for small texture maps (less than 32×32×32 bpp which fitinto one page) and are always accessed along a row. This matches up withmost 2D use of texture maps for font, icon and stipple pattern storage.Video data will also fall into this category.

Patch64. In this layout the pixel data is arranged into 64×16 patchesfor 32 bpp, 128×16 for 16 bpp and 256×16 for 8 bpp. This is thepreferred layout for the color buffer (desktop) so will only be usedwhen the texture units need to operate on this data directly, forexample to stretch blit a window.

Patch32_(—)2. The texture data is arranged into 32×32 patches, but alsopatched to a finer level so that one read always returns a 2×2 block oftexel data (for 32 bit texels), a 2×4 block for 16 bit texels or a 2×8block for 8 bit texels.

Patch2. The texture data is arranged into 2×2 patches. This is used fortexture maps where the total number of texels is less than 1K so it allfits into a page.

Linear or Patch64 texture formats can choose between top left and bottomleft origins, but the texture map must start on the natural boundary forthe texel size. For 8 bit texels this is on a byte boundary, for 16 bittexels this is on a 2 byte boundary and for 32 bit texels this is on a 4byte boundary.

The preferred layout for texture maps (1D or 2D) for use by 3D renderingis Patch32_(—)2 or Patch2 as this gives the minimum number of reads foran arbitrary orientation of the map, but for this to work the followingrules must be followed:

The texture maps are stored with the top left corner as the origin, i.e.texels at increasing u and/or v coordinates are at increasing memoryaddresses.

The texture map must start on the natural patch boundary for the texelsize. For 8 bit texels this is on a 4 byte boundary, for 16 bit texelsthis is on a 8 byte boundary and for 32 bit texels this is on a 16 byteboundary.

Patch32_(—)2 layout only make sense when the width of the texture map isgreater than the patch width (128 bytes). Using Patch32_(—)2 on texturemaps which are less than 128 bytes wide will just fragment the texturemap within the patch. This clearly wastes storage and may increase thenumber of page breaks. When the Texture Read Unit detects that the widthof a texture map is less than or equal to 128 bytes it will change thelayout from Patch32_(—)2 to Patch2 automatically. This allows mip mapsto be Patch32_(—)2 for the high resolution levels and Patch2 for the lowresolution levels.

It is the software's responsibility to set the layout to Patch32_(—)2 orPatch2 as appropriate when the texture map is downloaded. The hardwarewill write the texel data into the correct place but not switch layoutsautomatically.

The minimum width and height of a texture map (in any layout) is 2texels. If the width and/or height of a texture map is 1 (such as thelowest resolution map in a set of mip maps) then the texels must bereplicated to expand the offending dimension(s) to 2 texels. (This isnecessary as the bilinear index calculations will select set i0=0 andi1=0 with the interpolation coefficient set to combine some fraction oftexel 0 with texel 0, thus yielding texel 0. The Filter Unit cannot beconfigured to do this, but can achieve the same effect if the texel isrepeated.) If a 1×1 texture map has a border then the 3×3 map is storedas a 4×4 map as shown:

b0 b1 b2 b3 t0 b4 b5 b6 b7 b0 b1 b2 b2 b0 b1 b2 b2 b3 t0 b4 b4 b5 b6 b7b7

All the preceding comments on texture map layout for 1D and 2D texturemaps apply to the individual slices of a 3D texture map. The baseaddress of slice 0 is given in the TextureBaseAddr0 register and theoffset (in texels) between slices is given in TextureMapSize register.The TextureMapSize should be set to a value greater than or equal to theproduct of the width and height for a slice.

Address Calculation

The type of texture is checked and if it is a 3D texture map the baseaddress is set from TextureBaseAddr[0] register, the layout and texelsize are taken from TextureReadMode0 register and the width fromTextureMapWidth0.

If the texture is not a 3D texture map then the layout, texel size andwidth parameters are taken from the appropriate texture registers (theseregisters should be loaded the same for per pixel mip mapping). Thewidth is divided by 2 to the (map level), so the correct mip map widthis used. Note the width does not have to be a power of 2, so the dividemay have a remainder (which is ignored) so will fail past some maplevel. This is not a problem as mip maps will always be a power of twoin size and non mip maps will always have a map level of 0. The baseaddress is read from one of the 16 base address registers. The actualone used depends on the map level, the map base level and map max levelassociated with this texture as given by:

offset into base registers = min(texture map level + map base level, maxmap level)

so the allocation of the base registers between the two possibletextures is up to software.

The maximum width is 4095, but the minimum width depends on the layoutas the Patch2 and Patch32_(—)2 have some minimum requirements. If themip mapping forces the width below these minimum requirements then thewidth is forced to be the minimum allowed for the texel size. Theminimum texel widths are 8, 4 and 2 for 8, 16 and 32 bits per texelrespectively. The minimum width is one memory word (i.e. 16 bytes). Alsoif the width falls below 128, 64 or 32 texels for 8, 16 or 32 bits pertexel respectively any textures with a Patch32_(—)2 layout areautomatically set to Patch2.

The address is calculated as follows. (i and j are the coordinates ofthe required texel.)

For linear layout the pixel offset is:

bottom left origin: −j * width+i

top left origin: j * width+i.

For Patch64 the 2D ij coordinate space is mapped to a 1D address rangeas shown in FIG. 5, in which Pixel Offset (top left origin) is given by:

i % 64 + // i within a patch (i / 64) * 1024 + // i between patches (j %16) * 64 + // j within a patch (j / 16) +width +16 // j between patches

This can be converted into a simpler calculation just using shifts andadds:

(i & 0x3f) + ((i & 0xffc0) << 4) +((j & 0xf) << 6) + ((j & 0xfff0) *width)

For bottom left origin the equation is:

(i & 0x3f) + ((i & 0xffc0) << 4) − ((j & 0xf) << 6) − ((j & 0xfff0) *width)

For Patch2 the 2D ij coordinate space is mapped to a 1D address range asshown in the following equations:

Pixel Offset (top left origin) is given by:

i % 2 + // i within a patch (i / 2) * 4 + // i between patches (j % 2) *2 + // j within a patch (j / 2) * width * 2 // j between patches

This can be converted into a simpler calculation just using shifts andadds (only top left origin is supported):

(i & 0x1) + ((i & 0xfffe) << 1) + ((j & 0x1) << 1) + ((j & 0xfffe) *width)

For Patch32_(—)2 the 2D ij coordinate space is mapped to a 1D addressrange as shown in the following equations:

First calculate the offset to the corresponding 2×2 patch (recall thereare 16×16 within a 1K page):

i′ = i << 1 j′ = j << 1 (i′ % 16 + // i within a 32 × 32 patch (i′ /16) * 256 + // i between 32 × 32 patches (j′ % 16) * 16 + // j within a32 × 32 patch (j′ / 16) * width * 8) * 4 + // j between 32 × 32 patches// convert from 2 × 2 patches to texels

Add in the offset within the 2×2 sub patch:

i % 2 + // i within a patch (j % 2) * 2 // j within a patch.

This can be converted into a simpler calculation just using shifts andadds (only top left origin is supported):

(((i′ & 0xf) + ((i′ & 0xfff0) <<4) + ((j′ & 0xf) << 4) +  (((j′ &0xfff0) * width) >> 1)) << 2) +  (i & 0x1) + ( (j & 0x1) << 1).

For a 3D texture the TextureMapSize (in texels) is multiplied by the kindex (which selects the slice) to get the offset to the start of theslice the texel is on:

texelOffset+=k* TextureMapSize.

Note that the TextureMapSize does not have to be width x height, but canbe larger, if necessary.

Convert the texel offset into a byte offset, based on the texel size:

 8 bpp: byteOffset = texellOffset * 1 16 bpp: byteOffset = texelOffset *2 32 bpp: byteOffset = texelOffset * 4 64 bpp: byteOffset =texelOffset * 8

Add in the base address for the texture map. The base address is held asa byte address and must be aligned to the natural boundary for the texelsize. For a 16 bpp address the bottom bit must be 0. For a 32 bppaddress the bottom two bits must be zero. This is forced in hardware toremove any concerns of what happens if this condition is not true.

 8 bpp: byteAddr = baseAddr + byteOffset 16 bpp: byteAddr = (baseAddr &˜0x1) + byteOffset 32 bpp: byteAddr = (baseAddr & ˜0x3) + byteOffset 64bpp: byteAddr = (baseAddr & ˜0x7) + byteOffset

All address calculations are done to 32 bit and any overflow just wrapsaround. The i and j coordinates are zero extended up to the requiredwidth. The bottom 4 bits of the texel's byte address give the start bytein the memory's 128 bit width and the remaining upper bits give thememory address.

Primary Cache

An efficient texture cache is vital if a sustained texture rate of oneoutput texel per cycle is to be achieved and maintained. This is evenmore important when mip mapping as, in general, the zoom ratio isbetween 1:1 and 2:1 (output:input) so there is only moderate re-use oftexel data as we move from one pixel to the next.

One way to improve this is to try to hold enough texels in the cache sothat some re-use of them can be made on the next scanline. If this canbe done then only one new texel per output pixel on the second scanlineis needed for bilinear filtering, otherwise 2 new texels are needed. Formip mapping this translates to 1.5 new texels when making use ofscanline coherence or 3 new texels without. These figures can beimproved on by organizing the texel data in memory more efficiently andthis will be covered later once the organizational details have beencovered.

Clearly the best scheme is when all the texture map fits into cachehowever, at this point in time, this is not feasible except for thesmallest of texture maps (32×32 at 16 bits per texel).

The cache is divided into two banks so two independent textures can becached without any interference, or to hold two levels of a mip map, orslices of a 3D texture. When a single non mip mapped texture is beingused the two caches can be joined together so a larger texture map orpolygon can be rendered while still maintaining scanline coherency.

Span processing where the pixel mask (as part of the SpanStep message)is modified by the texel data does not use the primary cache.

The cache is always enabled and the only control over its operation theuser has is to be able to invalidate the cache. This needs to be donewhenever a new texture map is selected or the current texture map's datais edited in memory, thus causing any cached data become stale.

The cache is divided into two parts: a data part and a directory part.

Data Part

The data part holds the texel data and this can be found in the TextureFilter Unit so it is connected directly to the linear interpolators usedto implement the filtering operations.

The texel data is held in “raw” format so the cache holds the maximumnumber of texels and the texel data is converted “on the fly” as it isneeded into 8888 format the filter logic expects. The two texel formatswhich cannot be handled this way is the 8 bit indexed textures(replicating the conversion LUT is too expensive) and YUV 422 (theaddressing and data routing gets too complicated). In these two casesthe data is converted into 8888 formats and this is loaded into thecache.

Each cache line holds 128 bits of data and there are 256 cache lines ineach bank for RX and 64 cache lines in each bank for P3. (These sizesare for illustration only and may be changed later.) Each cache lineholds a 2×2, 4×2 or 8×2 patch of texels for 32, 16 and 8 bits per texelrespectively. In the 2×2 case the cache's performance is independent ofthe traversal direction through the texture map, however in the othertwo cases the “u” direction is preferred over the “v” direction.

The patch (2×2, etc.) has a fixed relationship to the origin of thetexture map such that the origin of the patch is always some integralmultiple of the patch size from the origin of the texture map. Thefollowing diagram shows the 2×2 patch arrangement within a texture map.The numbers in the brackets show the texel coordinates within thetexture map vary and the T0 . . . T3 are the corresponding filterregisters each texel is assigned. The grey areas are show the texelsheld in a memory word (16 bytes) for each size of texel. The texture mapmay also be patched at a higher level (32×32) to reduce the effect ofpage breaks but this is of no consequence to how the primary cachefunctions (see FIG. 6).

The organization of texture maps within memory is important and tries tomeet several criteria:

The performance should be independent of the traversal direction,especially for “large” texture maps (i.e. >32×32). Storing the texturemap in a linear fashion gives very good access times in the u directionbut poor access times in the v direction due to the page organization ofDRAMS. Storing the texture maps in a patch form (32×32 in our case for32 bit texels) equalizes the access times.

The memory width is very much wider than the texel width so each memoryread returns multiple texels. If the texel data in a memory word are allfor the same row then all the data is used when traversing in u (along arow) but very little is used in the v direction (along a column). The2×2 patch organization ensures that at least 2 texels can be used fromeach memory read for all traversal directions.

Texture maps are preferably stored in memory in one of the 2×2 patchedformats to give the best overall performance for general 3D use, howeverthis is not always possible or desirable. For example if the texturedata originates from an external source or is used to drive an externaldevice (i.e. a monitor) the layout of the data may be fixed and not in2×2 format. Alternatively the traversal direction may be known to alwaysbe in the u direction—examples of this are video scaling, fonts andgeneral 2D use.

When the texture map is stored in memory in a non 2×2 layout it isformatted into the 2×2 layout expected by the Filter Unit as it is readin.

The layout in memory for the various supported format is shown in FIGS.7A-7B. Each line is one memory word and the bit numbers are shown alongthe top. The tick marks are at byte intervals and the numbers inbrackets show how the texel coordinates vary within the memory word.

Note in the Linear and Patch64 cases only one alignment has been shown.The origin can be in 4, 8 or 16 places with respect to the width of thememory word (16 bytes) for 32, 16 or 8 bit texels respectively.

Directory Part

The directory part of the primary cache is held in this unit and issearched to find out if a texel is already in the primary cache, and ifso where. The search is done fully associatively and 8 texels (four percache bank) are searched simultaneously (to support the targetperformance of trilinear filtering or two bilinear filtered texels in acycle). The replacement policy is oldest first (FIFO). These parameterswill be justified later.

The key stored in the cache directory is formed from the texel's integercoordinate (i, j) and map level (or k for 3D texture). A bank of thecache cannot hold texels from different texture maps (texels from thedifferent levels in a mip map or from the different slices in a 3Dtexture can be held in the same bank). This means that the cache must beinvalidated whenever a new texture map is selected.

Why not use the texel's address as the key then the cache can holdtexels from different maps and does not need to be invalidated when adifferent texture map is selected? The answer is that the addresscalculation for 8 texels would need to be done in parallel and thiswould be quite expensive. This unit is supplied i0, i1 and j0, j1indices (these would be necessary for the address computation) and thefour texels (just considering one bank) are given by (i0, j0), (i1, j0),(i0, j1) and (i1, j1).

The typical search policies are fully associative, set associative anddirect mapped. These are graded from most expensive, most flexible(fully associative) to least expensive, least flexible (direct mapped).Set associative and direct mapped both rely on using a subset of indexbits to choose one (direct mapped) or a set of locations to search.

The access patterns through a 2D texture map follow an approximatestraight line. (It is actually a slightly curved line due to theperspective projection, but this is a minor effect and doesn't changeany of the reasoning.) The orientation of the line and its position isarbitrary and successive scanline will all follow on approximatelyparallel paths. The other variable to contend with is the width of thetexture map—this is variable (between texture maps) and a power of two.Given these constrains choosing a set of index bits to which will give agood distribution for each possible orientation of line looks animpossible task. A good distribution is vital otherwise, in the worstcase, all texels along a line could fall into one set (or a single entryfor direct mapped)—clearly this will defeat the purpose of a cache. Thefully associative search works equally well for all access patterns.

The common replacement policies are least recently used (LRU), oldest(FIFO), least frequently used and random. The LRU policy usually givesexcellent result but is the most expensive, however the approximatelyregular access patterns repeated from scanline to scanline will make theleast recently used page the same as the oldest page (at least withinthe same polygon). The oldest replacement policy is implemented by asimple counter which selects the entry to replace and is incrementedafter every replacement. The counter wraps within the available tablesize.

An alternative replacement policy (KeepOldest) is also supported whichis the same as oldest up until the point the cache is about to wrap on ascanline (i.e. earlier cache lines on the scanline are going to bereplaced). When the wrap occurs rather than starting back at the firstentry used on the scanline the last n entries are reused as scratchcache lines. This prevents scanline coherency from being lost for thewhole of the next scanline, but places some restrictions on the amountof expedited loading of the cache which can be done. It is difficult toknow how big the scratch area should be for the best trade off betweenmaintaining some scanline coherency and more stalling due to lesseffective cache loads. The value of n is programmable (theTextureCacheReplacementMode).

The size of the cache is a compromise—the larger the better, but itfollows the law of diminishing returns. The minimum useful size is basedon the number of texels visited along any path through the texture map.This will be the minimum of the texture map size and width of thepolygon. The cache is patched based so holds a minimum of two rows(maybe only partial rows) at a time. The filter may require texels fromtwo adjacent patches (in v) so in the worst case two pairs of rows areneeded. If a bank holds n bytes of data the maximum width of texture map(or texels along a polygon) which can be held while maintaining scanlinecoherency is n / (bytes per texel) / 4.

For P3 each bank has 1K bytes of storage so for 16 bit textures thecache works best when less than 128 texels are used for mip maps or 256texels for a single texture map (where both caches can be combined).

For RX each bank has 4K bytes of storage so for 32 bit textures thecache works best when less than 256 texels are used for mip maps or 512texels for a single texture map (where both caches can be combined).

The fully associative search is expensive and the two factors whichgovern the cost are the number of entries to search and the width of thekey. The number of entries is governed by the cache line length and thetotal amount of data in the cache bank. The cache line length and sizeof the cache have already been considered, but what about the key?

The key (as already described) holds the i and j index and the map level(3D textures will be considered shortly). The maximum width and heightof a map is 2050 (2K+a border) so the indices have 12 bits. The cacheline holds a 2×2 patch so the indices can be reduced by one bit to 11bits. The number of map level is needed here. In total the key is(11+11+4) bits or 26. This can be reduced down to 23 by realizing thatthe full 2050×2050 value can only occur on map level 0. Map level 1 hasa maximum size of 1026×1026 so by encoding the map into the upper bitsas shown in FIG. 8, the key width can be reduced.

Note that supporting a border on a 2K×2K map is probably an overkill forP3 (a 2K width map is useful for 2D applications to cope with a monitorwidth of 1600 or 1920). If the border was not supported on a 2K map thenthe key width could optionally be reduced to 21 bits.

Three dimensional texture maps have a larger key requirement—the mapbits are replaced by the k index. The i and j index are 11 bits as aboveand the k index is 12 bits. The even k slices are stored in bank 0 whilethe odd k slices are in bank 1 so the least significant bit of k can bedropped. This gives a key size of 33 bits and is larger than the totaladdress space most processors have. The key for 3D textures is formed byconcatenating the significant bits of the i, j and k indices together.The number of significant bits for the i and j indices are held inTextureReadMode0.Width and TextureReadMode0.Height respectively. A 23bit key allows a 3D texture to have 2²³ texels in it or a cuboid of256×256×128 without the risk of multiple texels aliasing to the same key(the reduced 21 bit key for P3 would allow a maximum cube size of128×128×128). Both these cuboids (or any other with the same volume) areprobably sufficient for a P3 class product but are marginal for an RXclass of product. For RX the key size has been increased to 27 bits toallow a maximum cube size of 512×512×512.

Combining Both Cache Banks

The two independent cache banks are ideal for mip mapping, 3D texturesand when two independent texture maps are being used but when a singletexture map is being used (a common occurrence) it is very wasteful tohave half the cache idle.

The Filter Unit can be put into a mode where the register files frombank 1 are used to extend the corresponding register files in bank 0.

The TextureReadMode0.CombineCaches bit is used to enable this mode ofoperation and when set the texels are alternately loaded into each bank.The texture 0 indices are used and are checked in both banks for theirpresence. Obviously only one bank should report that a texel is presentand this is used to select which register file is to supply the texeldata. This bank select bit is passed to the Filter Unit in theT4BorderColor to 7BorderColor bits as these are not needed in this modeof operation.

Loading the Cache

Any caching scheme is going to suffer from cache misses where the onlyoption open is to go and read the texel data from memory. The latencyfor the data to return may be anything from a few cycles to many tens ofcycles depending on how busy the memory is and if the texture requestintroduces a page break. (This assumes that the texture is resident inmemory or is a physical texture. If the texture is non-resident then thetime for it to be fetched from host memory could be thousands of cyclesat best or many more if the host has to respond to an interrupt, pagethe texture off disk and then download it.)

A fragment could cause from one to eight memory reads, although if thecache is working well and scanline coherency is being made use of thiswill very much reduced. (The pathological case is where bilinearfiltering is being done with a zoom ratio of 1:n, where n>1. In thiscase we are minifying the map and no coherence between adjacentfragments or scanlines can be exploited. From 1 to 4 reads per fragmentare needed depending on how the sample points interact with theunderlying 2×2 patch structure in the texture map.) FIG. 9 shows whichtexels the memory reads bring in and the corresponding output fragmentsthey will satisfy. The zoom ratio of 1:1 is used as this is the worstcase for mip mapping and occurs for the higher resolution map; the lowerresolution map will have a zoom ratio of 2:1 so any results for this maplevel will be twice as good. A texel size of 32 bits is also assumed sothese results are independent of any path orientation. The smallertexels sizes will give better results for X major paths.

From this figure it can be seen that for the interior fragments on evenrows no memory reads are required (because all the texel data was readin for the previous odd row) while for odd rows there is a read forevery other fragment, F(number of reads):

Even rows: F(0), F(0), F(0), F(0), F(0), F(0), F(0), etc. Odd rows:F(1), F(0), F(1), F(0), F(1), F(0), F(1), etc.

The next lower resolution map:

Row 0: F(0), F(0), F(0), F(0), F(0), F(0), F(0), etc. Row 1: F(0), F(0),F(0), F(0), F(0), F(0), F(0), etc. Row 2: F(0), F(0), F(0), F(0), F(0),F(0), F(0), etc. Row 3: F(1), F(0), F(0), F(0), F(1), F(0), F(0), etc.

Combining these together for the rows where there are accesses from bothlevels give:

F(2), F(0), F(1), F(0), F(2), F(0), F(1), etc.

Obviously for the first scanline and at the edges the number of readsper fragment are much larger and more frequent.

The cache management, address calculation and memory requests are beingprocessed many fragments in advance of the fragments the filter unit isworking on (determined largely by the depth of the M FIFO in this unit).So assuming the data is returned back from the memory quick enough itmay be possible to have the texel data loaded into the primary cachebefore it is needed. This can be achieved if the step message collectsthe texel data as it leaves this unit (in much the same way as occurs inthe LB Read Unit and FB Read Unit) but this requires write-throughregister files (probably not much of an issue) in the Filter Unit butdoes nothing to help the case where more than one load is needed tofulfil all the new texel data for this step message.

Multiple loads for a step message are common (as outlined above) buttypically there are spare load slots on steps which require no new data.We would like to make use of these spare slots otherwise we will take aperformance hit on some fragments. For the interior row shown thisamounts to 5 cycles for 4 fragments, but the edges will take a biggerhit.

Expedited loading of the cache has been implemented so texel data isloaded in advance of when it is needed, potentially by many cycles. Datareturned from the Memory Controller is loaded into the Filter Unit assoon as it is available rather than waiting for the initiating stepmessage.

Information to control the loading of the primary cache is passed to theoutput stage (called the Dispatcher) in the T FIFO. The step message ispassed in a parallel, but independent M FIFO. The Dispatcher will appendthe new texel data to any message, or if no message is going to be sentto the Filter Unit in this cycle it will inject it's own just to loadthe primary cache.

The expedited loading introduces a few problems of its own which need tobe solved to make the scheme viable:

(1) The expedited texels cannot overwrite texels which may be referencedby step messages which are queued up in the M FIFO until the originaltexel data has been used. This should be a rare occurrence and onlyhappen when the number of texels used on a scanline is approximately thesame as the texture cache can hold.

(2) Memory latency or just the amount of data required for a step maymean the step reaches the Dispatcher before all the data has been loadedinto the cache so the step message must be delayed.

The solution for (1) adopted is to only update the T FIFO with theexpedited load information while there are no steps in the M FIFO (orthe current step we are working on which has not been entered into the MFIFO yet) which reference the cache line assigned to be updated.

This entails a FIFO design which can have its valid entries tested forequality to see if any of them use the target cache line. The 72 bits[8×(8 address bits+1 valid bit)] of the FIFO width which hold the cacheaddress for each of the 8 texels the step references are available asindividual registers and have comparators so the test is done inparallel. The remaining width of the FIFO can be held in a normal FIFO.

Waiting for the offending step(s) to be flushed out of the M FIFOdegrades the performance gain we are trying to achieve, and in any casewill deadlock when the current step references the cache line we havechosen to replace. Instead we try to find a different cache line whichis not referenced by the current step or any queued up in the M FIFO.

Recall the preferred replacement policy is to replace the oldest entry,but in fact we can replace any entry which is not referenced. Whichentry should we replace? Some options are:

We could keep incrementing from the oldest entry looking for the firstentry we can replace. This is very simple but suffers from takingseveral cycles and we are very likely to bump texels one of thefollowing step message would like to use.

Change the cache policy to be LRU (or something else). Unfortunatelythis adds significantly to the cost of the cache so isn't really anoption.

Start looking for an unused entry at some offset from the currentposition, say at half the cache's size from where we are now. If thisfails then linearly search until an entry is found (which is alwaysguaranteed as the M FIFO is draining so freeing up cache lines at itgoes). This is a good compromise as it doesn't destroy the scanlinecoherency of the following steps (but may well do so for steps furtherinto the future), should just cost a single cycle in most cases and inthe limit is fail safe in that it will wait for the FIFO to drain.

The solution to (2) is for the Dispatcher to maintain a running count oftexels loaded into the Filter Unit. As each step message reaches theDispatcher the running count (called texelsLoaded in the behavioralmodel) it checked against the number of texels needed to be read by thisstep. If the texelsLoaded is greater than or equal to what the stepneeds the step is allowed to proceed to the Filter Unit, otherwise itstalls until sufficient data has been loaded. Once the step is allowedto proceed the texelsLoaded value is decremented by the number of loadsthe step message was waiting for.

The bottom line is this cache architecture and memory organization is upto 8 times more efficient than the GLINT MX as measured in number ofmemory reads per output fragment for 1:1 zoom ratio.

Secondary Cache

The secondary cache, at least compared to the primary cache is a verysimple affair. For normal texture mapping it is largely superfluousexcept in the following cases:

The texture layout in memory is Linear or Patch64. In these two casesthe texture must first be converted to 2×2 patch format before it isloaded into the primary cache. The secondary cache holds the data whilethis reformatting or aligning is being done. It also allows some re-useof data as the two memory reads needed to build up the 2×2 patch may beable to be used on the next 2×2 patch.

The texture map is an 8 bit indexed texture map. These are convertedinto 32 bit textures to be stored in the Filter Unit. The next primarycache load may well use 8 bit texels from the secondary cache ratherthan having read data from memory.

The texture data is going to be used for span processing. Spanprocessing does not use the primary cache so the secondary cache it itsonly way of reducing the memory bandwidth needed.

The secondary cache has four lines where each line holds 128 bits. Whyfour lines? There are two texture maps and each map can use two memoryreads when in Linear or Patch64 layout. The span processing use all fourlines to hold up to 512 bits of bit map data, but little re-use would benormally expected—the main gain is reading 128 bits of a font (forexample) in one go and extracting several rows worth of bit mask datafrom this.

The secondary cache is direct mapped (spans use a different algorithm)so the search and replacement policies are very simple and cheap. Thecache directory holds addresses (rather than indices as the primarycache does) and these may be logical addresses or physical addresses. Anextra bit identifies the type of address so a new logical address cannotalias with an old physical address, for example.

The secondary cache is always enabled and the only use control is to beable to invalidate it using the InvalidateCache command. This cacheshould be invalidated whenever texture data has been changed in memoryand this data may have been in the secondary cache. (This is never aproblem when the Virtual Texture Management changes a texture in memoryas the secondary cache holds the logical address and this is invariantunless software re-assigns this logical address to a new texture map.The act of updating the Logical Page Tables through the core willautomatically invalidate the secondary cache.)

Virtual Texture Management

Texture maps can be stored in physical memory or in logical/virtualmemory. If the texture map is stored in physical memory then it must bephysically contiguous and present before that texture is used.

The management of physical textures is complicated by the fact that anapplication can request more textures than can fit into on-card memoryso the textures need to be dynamically swapped, however this is not aneasy task to do well because:

The need to swapping and usage are decoupled in time by the DMA buffers.

The memory granularity is controlled by the texture map size so iscontinually changing.

Memory gets fragmented.

There is no clear replacement policy.

There are a number of solutions to solving this problem:

Increase the amount of physical memory to hold texture maps. This is notalways possible due to cost or board area constraints and in any casejust delays the point at which the problem will re-occur, rather thanfixing it altogether.

Allow textures to be executed out of host memory via the AGP or PCI bus.This is a similar solution to the previous one, except it doesn't havethe cost or board area constraints (at least as far as the graphicsboard is concerned). The downside of this is the bandwidth across theAGP bus is likely to be inferior to the bandwidth out of local memory.Also the latency for the texture data to arrive may degrade textureperformance. This method is supported by setting the HostTexture bit inthe TextureMapWidth registers. These texture reads will be done acrossthe AGP bus. The PCI bus can be used but because it lacks the efficientrandom in-page addressing AGP has the texture accesses will be veryslow. Note that there may be system reasons why such a method will notwork or work poorly. A system with a GLINT Gamma cannot do this type ofaccess (across AGP) and multiple RX's would require too much bandwidthand not interleave accesses very well.

The final solution is to treat the texture addresses as logical orvirtual addresses. The logical part allows texture maps to be stored innon-contiguous physical pages (a page is 4K bytes). This simplifies thememory management aspect as the granularity now is at the page level.The virtual part allows the dynamic paging of textures out of host orsystem memory with or without any assistance from the host CPU. This isdone on demand so borrows many of the techniques used for CPU memorymanagement. The virtual texture management (of which the logicaladdressing is a necessary sub-set) is implemented as standard in thisunit and will now be described in detail.

Host textures can also be managed; the main difference is that notexture data is downloaded, but is accessed “in situ” using the sideband addressing capability of the AGP texture execute mode.

Mapping an Address

A brief overview of the sequence of events which occur for a logicaltexture when the texel causes a primary cache miss will be described.Later on a detailed description will be presented.

The texel has its logical byte address calculated from it's integercoordinates, base address of the texture, texture map width, etc.

The logical page the logical address resides in is calculated and theTranslation Look aside Buffer (TLB) checked to see if the physical pageassigned to the logical page is present. If it is the physical addressis formed from the physical page number and the low order bits of thelogical address. Note the physical page is relative to the start of theworking set and not physical memory. The physical address is then postedto the memory controller.

If the logical page is not present in the TLB then the Logical PageTable entry for this logical page is read. If the resident bit is setthen the logical page is present in the working set and its physicalpage is read from the Logical Page Table. The TLB is updated so the nexttime this logical page is accessed the physical page is to hand. Thephysical address is formed from the physical page number and the loworder bits of the logical address and then posted to the memorycontroller.

If the logical page is not resident in the working set then detailsabout the page (its host address, target memory pool, etc.) is madeavailable to the host or DMA controller. (The DMA controller is in Gammafor RXs or is integrated into P3.) Sometime later the working set hasbeen updated with the new page of texture data and the Logical PageTable updated to show the faulting logical page is now resident and itsphysical address. The TLB is updated so the next time this logical pageis accessed the physical page is to hand. The physical address is formedfrom the physical page number and the low order bits of the logicaladdress and then posted to the memory controller.

Logical Page Mapping

The size of each page is always 4K bytes so the bottom 12 bits of atexel byte address give the byte within a page while the next 16 bitsgive the page number (the remaining 4 most significant bits areignored). This gives a maximum virtual texture size of 65536 pages or256MBytes. The working set can be any number of pages in size. Eachlogical page has 8 bytes of overhead (in the Logical Page Table) andeach physical page has 8 bytes of overhead (in the Physical PageAllocation Table). Some typical sizes for these tables are:

Managed Memory (pages / MBytes) Table Size 256 / 1 MByte 1 KBytes 512 /2 MByte 2 KBytes 1024 / 4 MByte  4 KBytes 2048 / 8 MByte  8 KBytes 4096/ 16 MByte 16 KBytes  8192 / 32 MByte 32 KBytes 

The Logical Page Table is typically much bigger than the Physical PageAllocation Table. The Logical Page Table must be physically contiguousand is allocated in local buffer memory. The Physical Page AllocatoinTable must be physically contiguous and is allocated in local buffermemory.

Memory Pools

The texture maps can be stored anywhere in the on card memory, howevertwo factors influence where the optimum place the texture should bestored:

The column/row/bank structure of the memory devices result in the memorybeing divided up into pages (not to be confused with logical or physicalpages previously discussed). (Some alignments and layouts are moreefficient than others.) Access times within a DRAM page are much fasterthan out of page accesses. SDRAM and SGRAM have multiple banks so canhave multiple open pages. When mip mapping or when two independenttextures maps are being used it is advantageous if the texture maps (oradjacent levels) are in different banks. (If two or more mip map levelsfit into the same DRAM page then this is not necessary.) Placing the twolevels or maps in the same bank, but different pages can cause a pagebreak for each texel access—something guaranteed to hurt performance.

The position of other buffers which are being simultaneously accessed isanother important consideration and texture map placement should avoidthese banks whenever possible.

For physical textures this assignment is totally up to software todecide, however for virtual textures the assignment to physical memoryis under hardware control. To assist the hardware in placing thetextures in an optimum memory bank the memory is divided up into fourmemory pools. Normally a pool would hold pages from a single memorybank.

The Logical Page Table identifies which pool each logical page should beassigned to when that logical page is loaded into memory.

Multi-RX Consideration

In a single RX or P3 system when a page fault occurs it would befeasible for the TextureDownload Controller to go and fetch the pageimmediately and then proceed once the page was in memory.

In a multi-RX system this method could also be used, however it is verylikely that a page fault in one RX will be followed by a page fault inanother RX for the same page. If each RX were to go and fetch thefaulting page independently then the effective texture downloadbandwidth will be reduced proportionally to the number of RXs in thesystem.

Each RX will accept a texture download at any time even if it has nooutstanding requests. This means that the first RX to fault will havethe faulting page of texture data loaded into itself and also all otherRXs. If the other RXs had faulted soon afterwards on the same page theywould remove their request when they detected this page beingdownloaded.

When a page fault is detected RX will inform Gamma (or the Gamma-likeTexture DMA Controller in P3) that it needs a page of texture data to bedownloaded. Gamma will either interrupt the host and the host softwarewill make available the texture data and start the download, orautomatically DMA from the hosts memory.

The following hardware signals are used to communicate between each RXand Gamma:

TextureDownloadRequest. This signal is asserted by RX to request atexture down-load. It is de-asserted once the texture download hasstarted.

TextureFIFOFull. This signal is asserted by RX when it is not able toaccept any more data being written into the TextureInput FIFO.

When Gamma has detected an RX is requesting a texture download it readsthree PCI registers in the requesting RX. These registers are:

HostTextureAddress. This register holds the host address where thetexture resides. This is either a physical address or a virtual address.A bit in the TextureOperation register identifies the type of address.If the address is a virtual address then an interrupt is generated andthe host will read the address and initiate the DMA once the data hasbeen made available.

LogicalTexturePage. This register holds the logical page for the texturedata and is returned back to the RXs in the two word header precedingthe actual texture data. In a multi-RX system all the RXs take thetexture download and not just the RX which requested it.

TextureOperation. This register holds the transfer length (=1024 words)in the bottom 11 bits and a bit to say if the host texture address is aphysical or virtual address (bit 11). If the address type is virtualthen the TextureDownload interrupt is generated, if enabled.

Gamma broadcasts the LogialTextureAddress and TextureOperation words tothe TextureInput FIFO before the actual texture data. The RXs on seeingthis information will remove any TextureDownloadRequest this transferwill satisfy and allocate space in its texture working set for the newtexture page.

TLB

The TLB is a fully associative table (or content addressable memory)which caches the recent logical to physical page mappings. It is firstcheck to see if the mapping we want for this page is present as this ismuch faster than having to query the Logical Page Table in memory. TheTLB search happens in a single cycle and is 16 entries for P3 and 64entries for RX. The replacement policy is oldest first.

A TLB can be classified according to its search policy, its replacementpolicy and its size. A justification for the chosen attributes will nowbe given.

The typical search policies are fully associative, set associative anddirect mapped. These are graded from most expensive, most flexible(fully associative) to least expensive, least flexible (direct mapped).Set associative and direct mapped both rely on using a subset of addressbits to choose one (direct mapped) or a set of locations to search.

The access patterns through a 2D texture map follow an approximatestraight line. (It is actually a slightly curved line due to theperspective projection, but this is a minor effect and doesn't changeany of the reasoning.) The orientation of the line and its position isarbitrary and successive scanline will all follow on approximatelyparallel paths. The other variable to contend with is the width of thetexture map—this is variable (between texture maps) and a power of two.Given these constrains choosing a set of address bits to which will givea good distribution for each possible orientation of line looks animpossible task. A good distribution is vital otherwise, in the worstcase, all addresses along a line could fall into one set (or a singleentry for direct mapped)—clearly this will defeat the purpose of a TLB.The fully associative search works equally well in all access patterns.

The common replacement policies are least recently used (LRU), oldest(FIFO), least frequently used and random. The LRU policy usually givesexcellent result but is the most expensive, however the approximatelyregular access patterns repeated from scanline to scanline will make theleast recently used page the same as the oldest page (at least withinthe same polygon). The oldest replacement policy is implemented by asimple counter which selects the entry to replace and is incrementedafter every replacement. The counter wraps within the available tablesize.

The size of the TLB is a compromise—the larger the better, but itfollows the law of diminishing returns. The minimum useful size is basedon the number of pages visited along any path through the texture map.Texture maps are preferably patched 32×32 (a patch at 32 bits per texelis the same size as a page).

For P3 the sweet spot is 256×256 mip mapped or 8 pages for level 0 plus4 pages for level 1 along a line. A 512×512 non mip mapped texture mapwill hit 16 pages along a line. The texel size is 16 bits so X-majorlines will hit half the number of pages. A 16 entry TLB covers thesesizes well.

For RX the sweet spot is 1024×1024 mip mapped or 32 pages for level 0plus 16 pages for level 1 along a line. A 2048×2048 non mip mappedtexture map will hit 64 pages along a line. A 64 entry TLB covers thesesizes well.

A TLB miss will cause a single read of the Logical Page Table—the costof this is difficult to quantify because is depends on how busy thememory system is and if it causes a page break. In the worst case wherethere are too few entries in the TLB to cover the length of the accesspath (i.e. no scanline to scanline coherence is being used) the TLB misstime will be amortised over a minimum of 16 texel reads. (This assumes aone to one mapping between telexes and pixels and takes into accountthat textures are stored as 2—2 patches—i.e. there are 16 2×2 minorpatches in a 32×32 major patch.)

The TLB can be invalidated by using the InvalidateCache command with bit2 set and this should be done whenever the host changes the Logical PageTable directly through the bypass. Changes to the Logical Page Table viathe UpdateLogicalTextureInfo command will automatically invalidate thoselogical pages which are updated, if present in the TLB.

Logical Page Table

The Logical Page Table has one entry per logical page and each entry hasthe following format:

Bit No Name Description  0-15 Physical These bits hold the physical pagenumber relative to Page the start of the working set where this logicalpage is held. If the page is not resident (next field) then these bitsare ignored (but will frequently be set to zero). This field is normallymaintained by RX, except when the page is marked as a HostTexture. 16Resident This bit, when set, marks this logical page as resident in theworking set. This field is normally maintained by RX, except when thepage is marked as a HostTexture. 17 Host This bit, when set, marks thislogical page as Texture resident in the host memory and it should beaccessed using AGP texture execute mode rather than downloading it. TheLength field should also be set to zero. 18-31 Reserved This field isnot used but is set to zero whenever the Resident bit is updated. 32-40Length This field holds the number of 128 bit words to transfer when apage fault occurs. This allows a page to hold a texture map smaller than4K without spending the extra download time on the unused words. Thereis no way to download to unused portion without overwriting the usedpart. When the physical page is in host memory the length field must beset to zero. This field is maintained by the host. 41-42 Memory Thisfield holds the memory pool this logical page Pool should be allocatedout of. This field is maintained by the host. 43 Virtual This bit, whenset, indicates the HostPage (next Host field) is a virtual page in hostmemory so cannot be Page accessed directly. Setting this bit willgenerate an interrupt and involve the host in providing this page oftexture data. When this bit is 0 the HostPage is the physical page andwill be read directly with no host intervention. This field ismaintained by the host. 44-63 Host This field holds the page in hostmemory where the Page texture data is held. This is a virtual host pageor a physical host page as indicated by the VirtualHostPage bit(previous field). This field is maintained by the host.

The first word in each entry is basically read and written by RX duringthe memory management activities unless the page is an host texture inwhich case the host is responsible for the first word as well. Thesecond word is written by the host (either directly via the bypass orvia the core using messages) and just read by RX.

The base address of the table is held in'the LogicalTexturePageTableAddrregister and is aligned to a 64 bit boundary. The number of entries inthe table is held in the LogicalTexturePageTableLength register and eachlogical page number is tested against this limit. If the logical pagenumber is out of range then the address is always mapped into page 0 ofthe working set and will never cause a texture download. (As a debug aidpage 0 of the working set can be missed out of the Physical PageAllocation Table and initialized to some distinctive texture map so anyout of range texture mappings cause a distinctive visual effect.) TheLogicalTexturePageTableLength is initialized to zero during reset whicheffectively disabled the logical and virtual texture management.

The table can be updated by the host directly via the bypass once thechip has been synced to make sure there are no conflicting accesses. ThePhysical Page Allocation Table must also be updated to remove thereference (if any) to the logical page being updated. The TLB should beinvalidated incase the updated Logical Page Table has left any staledata in the TLB. The InvalidateCache command (with bit 2 set) can beused to do this.

The table can also be updated via the normal command stream using theSetLogicalTexturePage command to set the first page to update. The datafor bits 32 . . . 63 is supplied with the UpdateLogicalTextureInfocommand and this will update the Logical Page Table at the previouslyset page and do all the necessary housekeeping. The logical page toupdate is auto-incremented so several consecutive table entries areupdated. Updates beyond the number of entries in the table (as set byLogicalTexturePageTableLength) are discarded and leave the memoryuntouched.

The logical table is updated by:

Memory Allocator to mark a logical page as non resident when itsallocated physical page is reclaimed and assigned to another logicaladdress.

The Download Controller to update the resident bit and physical pagefield once the download is complete.

Memory Allocation

When there is a new page of non host texture data to load into theworking set a physical page needs to be allocated to it from thespecified pool of memory. The least recently used page in the specifiedpool is used.

Keeping track of the least recently used page is done by a queue.Whenever a page is first accessed (easily identified by a TLB miss onthe page) it is moved to the head of the queue. It therefore followsthat the page at the tail of the queue is the least recently used so isthe one allocated to the new texture page. This physical page mayalready be assigned to a logical page so that logical page is marked asnon-resident in the Logical Page Table and removed from the TLB. (It ismost unlikely it is in the TLB as the working set will normally holdmany more pages than the TLB does.)

The queue used to track the physical pages is held in the Physical PageAllocation Table. This table has one entry per physical page and eachentry has the following format:

BitNo Name Description  0-15 Logical These bits hold the logical pagenumber this Page physical page has been assigned to. If no assignmenthas been made (or it has been removed) then the valid bit (next field)will be zero and these bits are ignored (but will frequently be set tozero). 16 Valid This bit, when set, marks this logical page as residentin the working set. This field is normally maintained by RX. 17-31Reserved This field is not used but is set to zero whenever the Residentbit is updated. 32-47 Next Page This field holds the page number of thenext page in the pool - i.e. the next recently used page. 36-63 PreviousThis field holds the page number of the Page previous page in the pool -i.e. the previous recently used page.

The Physical Page Allocation Table is not normally accessed by the host.The two exceptions are during power-on initialization and if pages areto be locked down. See later for information on these.

The NextPage and PrevPage fields are used to form a double linked listof the pages assigned to a memory pool. The double linked list is aclassic data structure for building queues from as it allows fixed timeinsertion and deletions. In this application a deletion can occur fromany queue entry, but insertions only occur at the head. The head entryis the most recently used physical page and the tail entry is the leastrecently used page.

A traditional linked list suffers from a linear search time, but bycombining it with an array (i.e. table) a constant search time to find agiven physical page is guaranteed—you just use the physical page numberto index into the table. This is important as a frequent operation is tomake a specific physical page the most recent. This involves searchingfor this page and updating the head (and maybe the tail) pointer to movethis page to the head of the queue.

Each memory pool has a head and tail page. These are held in theHeadPhysicalPageAllocation[0 . . . 3] and TailPhysicalPageAllocation[0 .. . 3] registers respectively and the index relates to each memory pool.These registers are initialized by software at the start of day, butthere after are read and written by the hardware.

The PrevPage field for the head page is ignored and will hold linkswhich should be ignored. Similarly for the NextPage field for the tailpage.

The maximum size the Physical Page Allocation Table needs to be is theamount of LB memory plus amount of FB memory (in MByes) divided by 4096.(There is no reason why the Physical Page Allocation Table could not besmaller and just cover the contiguous region set aside for dynamictexture management. Having it cover all the on card memory helps toillustrate some points.) This gives one entry for each 4K page on thecard. Many of these pages are not available for virtual texture storagebecause:

They hold the color buffers.

They hold the Z, stencil, etc. buffer.

They hold the overlay buffers.

They hold the video overlay buffers.

They hold non logical textures, icons, fonts, bitmaps, etc.

They hold the Logical Page Table.

They hold the Physical Page Allocation Table.

Run length encoded window ID information.

They hold logical textures which have been locked down.

These pages are not included in any of the four linked lists so areignored by the memory allocation hardware.

Programming Notes for Non Host Textures

Following is some general programming information on how the virtualtexture management hardware is used.

Start of Day Initialization

Before any logical or virtual texture management can be done there are anumber of areas which need to be initialized (in addition to the usualmode, etc. register initialization):

Space for the Logical Texture Page Table must be reserved in the localbuffer and the table initialized to zero. The LogicalTexturePageAddr andLogicalTexturePageTableLength must be set up.

Space for the working set must be reserved in the local buffer and/orframebuffer. This need not be physically consecutive pages. TheBasePageOfWorkingSet register is set up.

If virtual texture management is to be used then the followingadditional initialization is required:

Space for the Physical Page Allocation Table is reserved in the localbuffer and PhysicalPageAllocationTableAddr register is set up to pointto it.

Bits 0 . . . 31 of each entry in the Physical Page Allocation Table isset to zero—to clear the valid bit.

Each page entry in the Physical Page Allocation Table is associated toone of the four pools based on which bank of memory it resides in. Allthe pages in a pool are linked together as a double linked list bysetting the NextPage and PrevPage fields. The order is unimportant, butsequential is simplest. (It will soon get scrambled once the memoryallocation has been running for a while.) The PrevPage field for thefirst entry in the double linked list and the NextPage field for thelast entry can be set to any value as they are not used. Finally theHeadPhysicalPageAllocation and TailPhysicalPageAllocation registers forthis memory pool are updated with first and last page numbers. Eachmemory pool is set up like this. (Any number of memory pools up to amaximum of four can be set up. Unused memory pools don't have any pageslinked to them and must not be referenced in the Logical Texture PageTable.)

The texture management hardware is now ready to be used once logicaltextures have been created. The texture management can be done on aglobal basis so all contexts/APIs share the same mechanisms, or can bedone on a context by context basis.

Creating and Loading Texture Maps

The sequence of events when the application asks for a texture to beloaded are as follows:

Host memory to hold the texture map is allocated and locked down.(Virtual host memory could be used, however the driver will need torespond to every page fault and make the textures available in lockedphysical memory before starting the DMA off to download them. Other thanthe extra run time overhead and setting the VirtualHostPage flag in theLogical Texture Page Table entries the rest of the operations are thesame.) This memory is private to the driver or ICD and not accessible tothe application. The pages do not need to be contiguous.

The logical pages to use for the texture map are allocated from theLogical Texture Page Table. These may be new pages or currentlyassigned. If they are currently assigned then the texture managementhardware will do any necessary housekeeping to prevent aliasing ofphysical pages to the same logical page (thereby degrading theperformance, however still function correctly).

The host physical page (or host virtual page when host virtualaddressing is used) of each page reserved for the texture is found andthe HostPage field in for each corresponding entry in the LogicalTexture Page Table is updated with it.

The memory pool this texture is to be stored in is determined and eachlogical entry has its MemoryPool field set appropriately. (This, ingeneral, is likely to be a difficult thing to determine as the usage ofthe texture maps is not available Ideally texture maps which will beused simultaneously should be in different pools, unless they can bothfit into the same 4K page. )

The Length field for each logical entry will normally be set to 0×100(i.e. 4096 bytes), however as an optimization if only part of the 4Kpage is used (must be the lower part) then the number of 128 bit wordsused can be used instead.

The application's texture is copied into the previously allocated hostmemory and during the copy the texture map is patched and aligned asrequired by setting the texture map will be invoked with. (It isimpossible to do any patching or aligning on the fly as the page oftexture is downloaded as the download mechanism has no knowledge of thedimensions of the texture map, its base address, layout or texel size.)

The preferred way to update the Logical Texture Page Table is to use theSetLogicalTexturePage and UpdateLogicalPageInfo commands. TheSetLogicalTexturePage command takes the logical page to update in theleast significant bits. The UpdateLogicalPageInfo command sets bits 0 .. . 31 to zero and updates bits 32 . . . 63 with the given data. Theentry to update was set by SetLogicalTexturePage command and this isauto incremented after the update. All the necessary housekeeping isdone.

Alternatively the Logical Texture Page Table can be edited by softwareby reading and/or writing it directly to the table in memory by usingbypass memory accesses methods. In this case it is the software'sresponsibility to do the necessary housekeeping to remove any referencedto the updated logical pages in the Physical Page Allocation Table.

After this set up has been done the texture map can be bound and used.Note that the texture map (or pages of it) are not loaded until itactually used.

PreLoading Texture Maps

As mentioned above the texture map is only downloaded when it is used,but it is sometimes useful to ensure it is downloaded when it iscreated. This can be done by using the Load mode to load each logicalpage in the texture map. Alternatively when a texture map is bound (to acontext) you may want to ensure it is resident at this time, rather thanwait for a page fault. If the page is already resident then there is noneed to load it (as the Load mode would do) so the Touch mode can beused instead. These can be done using the command TouchLogicalPages.This command has the following data fields:

Bit No Name Description  0-15 Page This field set the first Logical Pageto touch. 16-29 Count This field holds the number of pages to touch.31-31 Mode This field is set to 3 to touch a page(s) or to 1 to load apage(s).

As each page is touched the corresponding texture data is downloaded.

Editing Texture Maps

To edit the texture map (for example as part of a TexSubImage operationin OpenGL) the host's copy is edited. The texture management hardware isnotified that the texture pages (if resident) are stale by using thecommand TouchLogicalPages to mark these pages as non resident. Thiscommand has the following data fields:

Bit No Name Description  0-15 Page This field set the first Logical Pageto mark as stale. 16-29 Count This field holds the number of pages tomark as stale. 30-31 Mode This field is set to 0 to mark the pages asstale (i.e. non resident). The primary texture cache is invalidated(using the InvalidateCache command) to ensure it doesn't hold any staletexel data for the texture map just edited.

Deleting Texture Maps

There is no real need to delete texture maps as simply reusing thelogical address achieves the same thing. If you really want to deletethe pages then the TouchLogicalPages command can be used to mark themnon resident. (Note that this doesn't mean that these pages are made theleast recently used pages so they get reused sooner—they will percolateto this status subsequently just through inactivity.)

Locking Down Texture Maps

The best way to have locked down texture maps (i.e. they don't getswapped out) is to avoid using the logical/virtual management and havethem as physical textures. If a texture is to be locked down after ishas been created as a logical texture then the only way to do this isfor the software to edit the Physical Page Allocation Table (and maybethe HeadPhysicalPageAllocation and/or TailPhysicalPageAllocationregisters for the effected pools). Before these edits can be done thesystem must be in a quiescent state so no texture downloads areguaranteed to start.

Virtual Host Textures

Virtual host textures are textures which live in virtual host memory sodo not need to be locked down into physical memory. As a result they arenot guaranteed to be present when a corresponding page fault occurs, andin any case the Logical Texture Page Table only holds the virtual pageaddress and not the physical page address.

The Logical Texture Page Table will have the VirtualHostPage bit set forthese logical pages and other than this the general setup (from RX'sviewpoint) is the same as when the bit is clear.

On a page fault the DMA controller cannot go and fetch the pageinformation directly but raises an interrupt.

On receiving this interrupt the TextureAddr PCI register is read andthis holds the 20 bit virtual address page for the faulting texturepage. (In P3 for P3 or in Gamma for RX; the one in RX should not beaccessed as the software will not know which RX in a multi-RX system isbeing serviced).) When the data is available in locked memory thephysical address where the data is located is written in to theTextureAddr PCI register. This will wake up the texture download DMAcontroller and it will do the download and finish any necessary housekeeping.

Using Logical Mapping without Virtual Management

Logical texture mapping can be used without the virtual part so atexture map does not need to be stored in consecutive physical pages inmemory, but the automatic loading of textures is never done. This allowstextures to be managed in the same way they are on GLINT MX, butsimplifies the memory management issues as the physical memoryallocation is now done on page size chunks, rather than variable texturemap sized chunks.

To work like this all current logical textures must be resident so apage fault will never occur. When a texture is created the softwareneeds to do two things:

Allocated the physical memory and update the Logical Texture Page Tablewith the logical to physical mappings. The physical page for eachcorresponding logical page is stored in bits 0 . . . 15 and the residentbit (bit 16) is set. The second word in each entry will never be used asthis is only accessed on a page fault.

 The Logical Texture Page Table can be modified directly via the bypass(with the normal caveats on syncing first) or can be updated via thecommand stream. The DownloadAddress register and DownloadData commands(see FB Write Unit for details) can be used to update an arbitraryregion of memory so can be used to update the logical entries in theLogical Texture Page Table. (The UpdateLogicalPageInfo command cannot beused as it zeros the physical page field and updates the fieldsconcerned with page faults. Also this command does housekeeping work onthe Physical Page Allocation Table, which presumably will not have beenset up if the virtual texture management is not being used.)

The texture map must be downloaded in to the physical pages. This can bedone via the bypass mechanisms or through the command stream. In eithercase it is the software's responsibility to do any patching andalignment consistent with how the texture map will be used. Note thetexture download mechanism which can do the patching doesn't have anymethod of remapping the addresses so cannot work with non contiguousphysical memory. The DownloadAddress register and DownloadData commandscan be used to download each page of texture (pre-patched, if necessary)into its corresponding physical page.

Programming Notes for Host Textures

Texture maps stored in host memory can be managed by the virtualmanagement hardware. This allows a texture map to be split over noncontiguous pages of host memory (without relying on the AGP GART tableto do the logical to physical mapping) and texture maps to be paged inand out of this memory.

The host pages are not part of the physical memory pool managed by thehardware so all host pages are allocated (or reallocated) by hostsoftware.

Start of Day Initialization

Assuming the range of logical pages reserved for host texture managementis already included in the length of the Logical Page Table then nofurther initialization of RX is needed other than to set up theBasePageOfWorkingSetHost register with the address of the region tomanage. This is a 256 MByte region and can be positioned anywhere in the4G host address range.

No changes to the Physical Page Allocation Table are needed.

Creating Logical Texture Maps

The sequence of events when the application asks for a texture to beloaded are as follows:

Host memory to hold the texture map is allocated and locked down.(Virtual host memory could be used, however the driver will need torespond to every page fault and make the textures available in lockedphysical memory before starting the DMA off to download them. As theseare AGP textures the length field (in the Logical Page Table) is zero sono download actually occurs, however it is convenient to use the samesynchronisation methods in the hardware implementation. Other than theextra run time overhead and setting the VirtualHostPage flag in theLogical Texture Page Table entries the rest of the operations are thesame.) This memory is private to the driver or ICD and not accessible tothe application. The pages do not need to be contiguous.

The logical pages to use for the texture map are allocated from theLogical Texture Page Table. These may be new pages or currentlyassigned. If they are currently assigned then the TLB should beinvalidated to prevent it from holding stale addresses.

Each logical page has its physical page, resident and host texturefields in the Logical Page Table updated with the corresponding hostphysical page where the texture is located. The length field must be setto zero (to disable a download from occurring). The pool field and thehostpage field are not used (but are available to software to holdinformation about this page).

The application's texture is copied into the previously allocated hostmemory and during the copy the texture map is patched and aligned asrequired by the setting the texture map will be invoked with.

The preferred way to update the Logical Texture Page Table is to use theDownloadAddress and DownloadData commands. The DownloadAddress commandtakes the byte address in memory of the Logical Page Table Entry toupdate. The DownloadData command writes its data to memory and then autoincrements the address. Two words are written per logical page entry.After the Logical Page Table has been updated the TLB must beinvalidated to prevent it holding stale data (use the InvalidateCachecommand with bit 2 set) and WaitForCompletion used to ensure the tablein memory has been updated before any rendering can start. (The writesto the Logical Page Table are done via the Framebuffer Write Unit so maystill be queued up on the subsequent TLB miss, hence stale page datawill be read from the Logical Page Table. The WaitForCompletion commandensures this cannot happen.)

Alternatively the Logical Texture Page Table can be edited by softwareby reading and/or writing it directly to the table in memory by usingbypass memory accesses methods. In this case it is the software'sresponsibility to Sync with the chip first to ensure no outstandingrendering is going to use a logical page about to be updated. The TLBstill needs to be invalidated after the bypass updates have been done.

After this set up has been done the texture map can be bound and used.

PreLoading Texture Maps

This is not a meaning full operation with host textures (unless they arevirtually managed in which case they can be touched like the non hosttextures can—see earlier) as the texels are read on demand and notdownloaded as pages.

Editing Texture Maps

To edit the texture map (for example as part of a TexSubImage operationin OpenGL) the host's copy is edited. The primary texture cache isinvalidated (using the InvalidateCache command) to ensure it doesn'thold any stale texel data for the texture map just edited.

Deleting Texture Maps

There is no real need to delete texture maps as simply reusing thelogical address achieves the same thing.

Virtual Host Textures Virtual host textures are textures which live invirtual host memory so do not need to be locked down into physicalmemory. As a result they are not guaranteed to be present when acorresponding page fault occurs, and in any case the Logical TexturePage Table only holds the virtual page address and not the physical pageaddress.

The Logical Texture Page Table will have the VirtualHostPage bit set,the resident bit clear, the host texture bit set and length field zerofor these logical pages.

The DMA controller will raise an interrupt (even though no download isneeded the DMA controller is involved so the same software interface canbe used).

On receiving this interrupt the TextureAddr, LogicalPage andTextureOperation PCI register are read (in P3 for P3 or in Gamma forRX—the one in RX should not be accessed as the software will not knowwhich RX in a multi-RX system is being serviced) to identify thefaulting texture page. When the data is available in locked memory theLogical Page Table is updated via the bypass and the TextureAddr PCIregister is written (the data is not used). The write to the TextureAddrregister will wake up the texture download DMA controller but becausethe length field is zero no download is done or physical page (from thePhysical Page Allocation Table) allocated. The TLB will be automaticallyinvalidated.

In servicing the interrupt a physical page (or pages if the interrupt isused to allocate a whole texture rather than just a page) must beallocated by software. If these physical pages are already assigned thenthe corresponding logical pages must be marked as non resident in theLogical Texture Page Table. If these newly non resident logical pagesare subsequently accessed (maybe by a queued texture operation) theythemselves will cause a page fault and be re assigned. Hence noknowledge of what textures are waiting in the DMA buffer to be used isnecessary. The physical pages are allocated from the host working setwhose base page is given by BaseOfWorkingSetHost register.

Special Types of Textures

3D Textures

A 3D texture map is one where the texels are indexed by a triplet ofcoordinates: (u, v, w) or (i, j, k) depending on the domain. Suchtextures are typically used for volumetric rendering.

The texture map is stored as a series of 2D slices. Each slice is storedin an identical fashion to all other 2D texture maps. The first slice(at k=0) is held at the address given by TextureBaseAddr0 and theremaining slices are held at integral multiples of TextrueMapSize(measured in texels) from TextureBaseAddr0.

3D texture mapping is in this unit is enabled by setting the Texture3Dbit in TextureReadMode0 (the same bit in TextureReadMode1 is alwaysignored). The layout, texel size, texture type and width should be setup the same for texture 0 and texture 1.

When 3D texture is enabled then any bits to control dual textures or mipmapping are ignored.

The storage of 3D texture maps is not optimal for volumetricrendering—ideally the texture is stored in 3D patches (at the 2×2×2level and at the 32×32×32 level, or equivalents). Some access paths(primarily along the k axis) will exhibit a high number of page breaksso be slower than paths primarily along the i or j axis. No effort hasbeen made to address this as the inclusion of 3D textures is more afunctional rather than a performance issue (yet!).

CombinedCache mode bit should not be set when 3D textures are beingused.

Bitmaps

Bitmap data can be stored in memory and accessed via the texture mappinghardware. The resulting “texel” data is treated as a bitmap and used tomodify the pixel or color mask used in a span operation.

The bitmap data can be held at 8, 16, 32 or 64 bit texels and is zeroextended (when necessary) to 64 bits before being optionally byteswapped, optionally mirrored, optionally inverted and ANDed with thepixel mask or the color mask. The primary texture cache is not used forthis data, however the secondary cache is.

The bitmap data can only be held in Linear or Patch64layouts—Patch32_(—)2 or Patch2 formats are not supported, however nointerlocks prevent their use—the results are just not interesting oruseful. The bitmap data can be stored as logical or physical textures.

The bitmap data can be held as packed 8, 16, 32 or 64 bit data, usuallywith one scanline of the glyph held per texel. Glyphs wider than 64 bitswill take multiple texels to cover the width. Packing multiple scanlinestogether reduces the waste of memory (in MX the texel size was limitedto 32 bits for spans), and makes the caching more efficient. Before thetexel can be used it is processed as follows:

The texel is zero extended up to 64 bits.

The texel is byte swapped according to TextureReadMode0.ByteSwap field.If the 64 bit word has bytes labelled: ABCDEFGH then the three bits swapthe bytes as follows:

Bit 2 Bit 1 Bit 0 swapped (long swap) (short swap) (byte swap) ABCDEFGH0 0 0 ABCDEFGH 0 0 1 BADCFEHG 0 1 0 CDABGHEF 0 1 1 ABDCEPGH 1 0 0EFGHABCD 1 0 1 FEHGBACD 1 1 0 GHEFCDAB 1 1 1 HGFEDCBA

Next the texel is optionally mirrored. This is controlled by theTextureReadMode0.Mirror bit. The mirror swaps bits:

(0,. 63), (1, 62), (2, 61), . . . (31, 32).

The texel is next optionally inverted under control of theTextureReadMode0.Invert bit.

When TextureReadMode0.OpaqueSpan is zero the texel is ANDed with thepixel mask to remove pixels from the mask. WhenTextureReadMode0.OpaqueSpan is one the texel is ANDed with the colormask (in the SpanColorMask message) to control foreground/backgroundcolor selection.

Windows normally supplies its bitmasks as a byte stream with successivebytes controlling 8 pixel groups at increasing x (i.e. towards the rightedge). Bit 7 within a byte controls the left most pixel (for that group)and bit 0 the right most pixel. To match up the pixel mask order (bit 0controls the left most pixel, bit 63 the right most pixel) the threebyte swap bits are all set and the mirror bit set.

Indexed Textures

Indexed textures are a special case because they are stored as 8 bittexels and expanded to 32 bit texels when loaded into the Texture FilterUnit (the expansion happened in the Texture LUT Unit). This makes theaddressing and cache management slightly more complicated as theaddressing uses the 8 bit texel size, while the cache management usesthe 32 bit texel size.

The secondary cache holds the texture data in its 8 bit format soreduces the number of memory reads when the access path is mainly in uacross the texture map.

YUV 422 Textures

YUV textures are a special case because two texels are stored in a 32bit word (so in this sense they are 16 bit texels), however the U and Vcomponents are shared so the 32 bit word represents two 24 bits texels(the spare “alpha” byte is set to 255). If the input bytes in the 32 bitword are labelled:

Y1 V0 Y0 U0 (U0 in the 1s byte)

then the two output words are formed (in the internal format):

255 V0 U0 Y0 and 255 V0 U0 Y1 (Y in the 1s byte)

This arrangement of the YUV pixels in memory is called YVYU, but analternative memory format (called VYUY) is also supported. In this casethe bytes are labelled:

V0 Y1 U0 Y0 (Y0 in the is byte)

Borders

Borders (in the OpenGL sense) are only used when the filter mode isbilinear and the wrapping mode is clamp. In this case when one of thefilter points go outside the texture map the border texel is read (ifpresent) or the border color is used (if absent). The border, ifpresent, still needs to be skipped over and this will have already beendone by incrementing the i, j indices before they get to this unit.

The width of a texture map is given by (2^(n)+2b) where b is 0 for noborder or 1 with a border. Unfortunately it is not good enough to setthe texture map width to this value as the lower resolution mip maplevels will “divide out the border” as the width is divided by 2 foreach successive level. The TextureMapWidth0 and TextureMapWidth1registers hold the width of the texture map without the border (in bits0 . . . 11) and if a border is present the border bit (bit 12) inTextureMapWidth0 or TextureMapWidth1) is set. If a 1×1 texture map has aborder then the 3×3 map is stored as a 4×4 map as shown:

b0 b1 b2 b3 t0 b4 b5 b6 b7 b0 b1 b2 b2 b0 b1 b2 b3 b3 t0 b2 b4 b5 b6 b7b7

Texels which fall into the border when no border is present are flaggedby the Texture Index Unit so these texels are not checked in the cacheand no texels read from memory. The T0BorderColor . . . T7BorderColorflags used for this purpose are also passed to the Texture Filter Unitwhere they select the BorderColor0 (T0 . . . T3) or BorderColor1 (T4 . .. T7) registers instead of the primary cache to provide the texturedata. The BorderColor0 and BorderColor1 registers would normally be setthe same value for OpenGL when mip mapping.

FIG. 4A and FIG. 4B are a pair of flow charts which show how a textureis loaded, depending on whether a cache miss occurs.

FIG. 4B shows actions in the Primary Cache Manager. If a cache missoccurs (test 421), the details of the missing texel are obtained (step423), and the next free cache line is looked up (step 425). A readcommand is then issued to the address generator (step 427), specifyingthe free cache line as the return address. The address generator updatesthe T FIFO after the read request has occurred. A message is thenwritten into the M FIFO with details of the cache lines used, fragmentdetails, and the number (if any) of additional cache loads which havenow occurred.

FIG. 4A shows actions in the Dispatcher. If the T FIFO or the Texel DataFIFO are not empty (test 401), then the data in the Texel Data FIFO iswritten (step 403) into the cache data line given by the T FIFO. TheCache lines loaded count is then updated (step 405), and the entryflushed from both FIFOs (step 407). Thereafter, if the M FIFO is notempty (test 409), and if the count of cache lines loaded indicates (test411) that the cache would not be overfilled by the new cache lines, afragment message is sent off (step 413) to the Filter Unit, and theactive entry is flushed (step 415) from the M FIFO. The count of cachelines loaded is then adjusted (step 417) by the number of new linesneeded.

Implementation

Following are some details of a sample implementation.

Overview

A block diagram of the unit is shown in FIG. 10. The overall unit issplit into 7 sub-units and these are basically organized into threegroups:

The Primary Cache Manager, Address Generator and Dispatcher form thecore of the unit and work in a similar way to the other read units. Thelogical address translation is handled by the Address Mapper and TLB.The dynamic texture loading is handled by the Memory Allocater and theDownload Controller.

The interfaces between all the units are shown as FIFOs, but most of theFIFOs are just a register with full/empty flags for simple handshaking.The single deep FIFOs have been used as they clearly delineate thefunctionality between units and allow a single sub unit to beresponsible for a single resource.

The two shared resources which are managed in this way are the TLB andMemory Allocater. The TLB is mainly queried by the Address Mapper butthe Memory Allocater needs to invalidate pages when a physical page isre-assigned. The Memory Allocater will allocate pages when requested bythe Download Controller, but also needs to mark pages as “most recentlyused” when requested by the Address Mapper.

There are two read/write ports to the Memory Controller used to accessthe Logical Page Table and the Physical Page Allocation Table—these are64 bit ports and are not FIFO buffered. There is no point in trying toqueue up reads or writes on these ports as the texture process stallsuntil these operations are satisfied.

The read port to the Memory Controller is used to read texture data andhas a deep address FIFO and return data FIFO to absorb latency.

The write port to the Memory Controller is used by the DownloadController to write texture data into memory during a download. The pathfrom the Texture Input FIFO to the Memory Controller is 128 bits wide sothe maximum download bandwidth can be sustained.

All the controlling registers (TextureReadMode, TextureMapWidth,TextureBaseAddr, etc. are all held in the Primary Cache Manager so theresponsibility for loading them from the message stream, context dumpingand readback is all concentrated in one place. This does mean thatbefore any of them can be updated any outstanding work which may dependon them has to be allowed to complete. To make things simpler before anyof these registers (see behavioral model for a full list) is updated theall the sub units need to be idle (as indicated by the FIFOs linkingthem be empty).

The sequence of events when a step message arrives under variousconditions:

When All the Texel Data is in the Primary Cache

The texels: (i0, j0, map), (i1, j0, map), (i0, j1, map), (i1, j1,map)for texture 0 and for texture 1 are checked in parallel in the PrimaryCache Manager to see if they are in the primary cache.

The step message, with the address of each texel filled in, is writtento the M FIFO and the texel read count field on this step set to zero.This part of the processing all happens in the same cycle so thefragment throughput is maintained.

Some time later this step message reaches the Dispatcher and is passedon as soon as the following unit can accept it.

When Two Texels (from different texture maps) are NOT in Primary Cachebut are in Physical Memory

The texels: (i0, j0, map), (i1, j0, map), (i0, j1, map), (i1, j1, map)for texture 0 and for texture 1 are checked in parallel in the PrimaryCache Manager to see if they are in the primary cache.

One texel from texture 0 and one texel from texture 1 miss the primarycache. The cache line allocation for both banks is checkedsimultaneously and the missing texels passed to the Address Generatorvia the AG0 and AG1 FIFOs for the corresponding banks. The step message,with the address of each texel filled in, is written to the M FIFO andthe texel read count field on this step set to two. This part of theprocessing all happens in the same cycle so the fragment throughput ismaintained.

The Address Generator will process the texel reads one at a time. Itcalculates the address for the texel in memory using the i, j and mapvalues together with the appropriate TexelReadMode and TextureMapWidthvalues. The address is checked to see if it is in the secondary cache,and if it is then instructions to load the primary cache from thesecondary cache are sent down the T FIFO. A more common case (forPatch32_(—)2 or Patch2 layout) is that the secondary cache doesn't holdthe texel so the Address Mapper is given the address and its type(logical or physical) via the AM FIFO.

The Address Mapper checks in the TLB to see if the logical page ispresent and, if so, what its corresponding physical page is. The logicalpage is not in the TLB so the Address Mapper reads the entry in theLogical Texture Page Table for this logical page. The entry returns aresident bit and a physical page number. The resident bit is set so thephysical page number is now known. The physical memory address isderived from the physical page and low order bits of the logical addressand passed to the Memory controller. The TLB is updated so this logicalpage is the most recent one and its corresponding physical pagerecorded. Some time later this step message reaches the Dispatcher andif the outstanding texel data as shown by the texel read count field)has been loaded into the primary cache (in the Filter Unit) the step ispassed on as soon as the following unit can accept it. If, however theoutstanding texel data has not been loaded then the step message isstalled until it has.

When Two Texels (from different texture maps) are not in Primary CacheNOR in Physical Memory

The texels: (i0, j0, map), (i1, j0, map), (i0, j1, map), (i1, j1, map)for texture 0 and for texture 1 are checked in parallel in the PrimaryCache Manager to see if they are in the primary cache.

One texel from texture 0 and one texel from texture 1 miss the primarycache. The cache line allocation for both banks is checkedsimultaneously and the missing texels passed to the Address Generatorvia the AG0 and AG1 FIFOs for the corresponding banks. The step message,with the address of each texel filled in, is written to the M FIFO andthe texel read count field on this step set to two. This part of theprocessing all happens in the same cycle so the fragment throughput ismaintained.

The Address Generator will process the texel reads one at a. time. Itcalculates the address for the texel in memory using the i, j and mapvalues together with the appropriate TexelReadMode and TextureMapWidthvalues. The address is checked to see if it is in the secondary cache,and if it is then instructions to load the primary cache from thesecondary cache are sent down the T FIFO. A more common case (forPatch32_(—)2 or Patch2 layout) is that the secondary cache doesn't holdthe texel so the Address Mapper is given the address and its type(logical or physical) via the AM FIFO.

The logical page is not in the TLB and the resident bit in the LogicalTexture Page Table is clear so the Address Mapper writes to the hostphysical address (read from the page table) into the PCIHostTextureAddress register, the logical page into the PCILogicalTexturePage register and the transfer length, memory pool andaddress type (set to host physical for this description) into the PCITextureOperation register. Finally the PCI TextureDownloadRequest bit isset. The Address Mapper will wait for the Texture Download Completesignal to be asserted by the Download Controller.

Some time later the Texture DMA Controller (in Gamma for a RX system, orin P3 for a P3) will respond to the TextureDownloadRequest bit beingset. It will write the logical address, transfer length and memory poolinto the Texture Input FIFO and then follow this data with the page oftexture map data.

The Download Controller on receiving the logical page and poolinformation in the Texture Input FIFO will make a request to the MemoryAllocator via the MAC FIFO for the physical page to use for the downloadjust about to start. The Memory Allocator will use the Physical PageAllocation Table to allocate a physical page and ask the TLB (via theTLB I FIFO) to invalidate the logical page previously occupying (if any)the newly allocated physical page. The Memory Allocator also updates theLogical Texture Page Table to mark the logical page as being resident atthe new physical page. The physical page is returned back to theDownload Controller via the MAD FIFO.

The Download Controller on receiving the physical page in the MAD FIFOwill transfer the texture data in the Texture Input FIFO to the givenphysical page. Once this is done the TextureDownloadComplete signal isasserted which releases the Address Mapper to complete its task.

The Address Mapper will read the Logical Texture Page Table entry forthis logical page and now that the page is resident the physical page isread from the Logical Texture Page Table. The physical memory address isderived from the physical page and low order bits of the logical addressand passed to the Memory Controller. The TLB is updated so this logicalpage is the most recent one and its corresponding physical pagerecorded.

Some time later this step message reaches the Dispatcher and if theoutstanding texel data (as shown by the texel read count field) has beenloaded into the primary cache (in the Filter Unit) the step is passed onas soon as the following unit can accept it. If, however the outstandingtexel data has not been loaded then the step message is stalled until ithas.

Memory Interfaces

The Texture Read Unit has connections to four ports in the MemoryInterface. The four ports are (in priority order from highest tolowest). This is an absolute priority and not based on any page breakconsiderations:

Memory Allocator Port

Address Mapper Port

Texture Write Port

Texture Read Port

Note that the first two ports are not FIFO buffered, so they will blocksubsequent texture processing until their read or write request havebeen serviced.

Texture Read Port

This port is used to read texel data from memory. The addresses (afterany necessary translation) are written into the Tx Addr FIFO andsometime later the 128 bits worth of data are returned via the Tx DataFIFO.

The following information is passed to the Memory Controller in a FIFO:

Bit No. Name Width Description 0-1 Type  2 Indicates what the targetmemory is. The options are: 0 = FB Memory 1 = LB Memory 2 = PCI 2-29Addr 28 The read address of the 128 bits of memory data.

The following information is passed back from the Memory Controller in aFIFO:

Bit No. Name Width Description 0-127 Data 128 The data read from thememory.

Texture Write Port

This port is used by the Download Controller to write texture data intoits allocated physical page. It is also used to update the LogicalTexture Page Table to mark the page as being resident once it has beendownloaded.

The following information is passed to the Memory Controller in a FIFO:

Bit No. Name Width Description 0-1 Type  2 Indicates what the targetmemory is. The options are: 0 = FB Memory 1 = LB Memory 2 = PCI 2-29Addr 28 The write address of the 128 bits of memory data. 30-45ByteEnables 16 A high on a bit enables that byte to be written. The lsbyte enable corresponds to data bits 0-7. 46-173 Data 128  The data tobe written to the memory.

The following information is passed back from the Memory Controller:

Bit No. Name Width Description 0 TrWrComplete 1 This signal is assertedby the memory controller when the FIFO is empty and all writes from thisport, the Memory Allocator Port and the Address Mapper Port have beenwritten to memory so can be read from another port.

Memory Allocator Port

This port is used to update the Logical Texture Page Table withinformation from the host and to remove references from a physical pageto a logical page in the Physical Page Allocation Table. The port is 64bits wide (to save routing a 128 bit data bus from the MemoryController). The read and write operations are buffered by a singlelevel FIFO (to provide a simple interface) so will stall until theiroperations are satisfied.

The following signals are passed to the Memory Controller (MC):

Bit No. Name Width Description 0-1 Type  2 Indicates what the targetmemory is. The options are: 0 = FB Memory 1 = LB Memory 2 = PCI 2Command  1 0 = Write, 1 = Read 3-31 Addr 29 The write address of the 64bits of memory data. 32-39 ByteEnables  8 A high on a bit enables thatbyte to be written. The ls byte enable corresponds to data bits 0-7.40-103 WrData 64 The data to be written to the memory.

The following signals are passed from the Memory Controller (MC):

Bit No. Name Width Description 0 RdData 64 The data read from memory

Address Mapper Port

This port is used to update the Physical Page Allocation Table as pagesare allocated or made the most recent accessed page. It is also used tomark logical pages in the Logical Page Table as non resident when theassociated physical page is re-used. The port is 64 bits wide (to saverouting a 128 bit data bus from the Memory Controller). The read andwrite operations are buffered by a single level FIFO (to provide asimple interface) so will stall until their operations are satisfied.

The following signals are passed to the Memory Controller (MC):

Bit No. Name Width Description 0-1 Type  2 Indicates what the targetmemory is. The options are: 0 = FB Memory 1 = LB Memory 2 = PCI 2Command  1 0 = Write, 1 = Read 3-31 Addr 29 The write address of the 64bits of memory data. 32-39 ByteEnables  8 A high on a bit enables thatbyte to be written. The ls byte enable corresponds to data bits 0-7.40-103 WrData 64 The data to be written to the memory.

The following signals are passed from the Memory Controller (MC):

Bit No. Name Width Description 0 RdData 64 The data read from memory

Interface with Texture Index and Texture Filter Units

This unit receives a substantial amount of information about thefiltering process and the texels taking part in it from the TextureIndex Unit. Some of this information (such as the interpolationcoefficients) are not used by this unit and are just passed through. Theactive step messages and the span step messages are extended to carrythe extra information. The following table describes the format of thesemessages:

Bit No Name Description 0-95 — These bits carry the normal data presentin an ActiveStepX, ActiveStepYDomEdge, SpanStepX or SpanStepYDomEdgemessage. 96-107 f0i0 This field holds i0 index for texture 0, even mipmaps or even slices for 3D textures. The least significant bit of thecomputed index is not needed so the original 12 bit number has beenreduced to 11 bits. 108- f)i1 This field holds i1 index for texture 0,even 119 mip maps or even slices for 3D textures. The least significantbit of the computed index is not needed so the original 12 bit numberhas been reduced to 11 bits. 120- f0j0 This field holds j0 index fortexture 0, even 131 mip maps or even slices for 3D textures. The leastsignificant bit of the computed index is not needed so the original 12bit number has been reduced to 11 bits. 132- f0j1 This field holds j1index for texture 0, even 143 mip maps or even slices for 3D textures.The least significant bit of the computed index is not needed so theoriginal 12 bit number has been reduced to 11 bits. 144 T0Valid Thesebits show which texels are valid texels 145 T1Valid as a function of thefilter type and the map 146 T2Valid type (1D or 2D) and will limit theaddresses 147 T3Valid checked in the primary cache and hence any texturereads ultimately done. 148 T0BorderColor These bits show which texelsare to use the 149 T1BorderColor border color instead of texel data.These are 150 T2BorderColor only taken into account for valid 151T3BorderColor combinations of indices (see previous field). 152- f0mapThis field holds the map level the texels 155 (T0 . . . T3) are on. 156-f1i0 This field holds i0 index for texture 1, odd mip 167 maps or oddslices for 3D textures. The least significant bit of the computed indexis not needed so the original 12 bit number has been reduced to 11 bits.168- f1i1 This field holds i1 index for texture 1, odd mip 179 maps orodd slices for 3D textures. The least significant bit of the computedindex is not needed so the original 12 bit number has been reduced to 11bits. 180- f1j0 This field holds j0 index for texture 1, odd mip 191maps or odd slices for 3D textures. The least significant bit of thecomputed index is not needed so the original 12 bit number has beenreduced to 11 bits. 192- f1j1 This field holds j1 index for texture 1,odd mip 203 maps or odd slices for 3D textures. The least significantbit of the computed index is not needed so the original 12 bit numberhas been reduced to 11 bits. 204 T4Valid These bits show which texelsare valid texels 205 T5Valid as a function of the filter type and themap 206 T6Valid type (1D or 2D) and will limit the addresses 207 T7Validchecked in the primary cache and hence any texture reads ultimatelydone. 208 T0BorderColor These bits show which texels are to use the 209T1BorderColor border color instead of texel data. These are 210T2BorderColor only taken into account for valid combinations 211T3BorderColor of indices (see previous field). 212- f1map This fieldholds the map level (T4-T7) are on. 215 216- 10 Interpolationcoefficient between (T0, T1) and 224 (T2, T3) in 1.8 unsigned fixedpoint format. 225- 11 Interpolation coefficient between (T0, T2) and 233(T1, T3) in 1.8 unsigned fixed point format. 234- 12 Interpolationcoefficient between (T4, T5) and 242 (T6, T7) in 1.8 unsigned fixedpoint format. 243- 13 Interpolation coefficient between (T4, T6) and 251(T5, T7) in 1.8 unsigned fixed point format. 252- 14 Interpolationcoefficient between (T0, T1, T2, 260 T3) and (T4, T5, T7, T7) in 1.8unsigned fixed point format.

The active step messages are extended to carry the extra information.The following table describes the format of these messages:

Bit No Name Description 1-70 — These bits carry the normal data presentin an ActiveStepX, ActiveStepYDomEdge message. 71-80 A0 also called Thisfield identifies the cache line (bits 2-9) T0 cacheLine0 is in and thebyte position in the word (bits 0-1). 81-90 A1 also called This fieldidentifies the cache line (bits 2-9) T1 cacheLine1 is in and the byteposition in the word (bits 0-1). 91- A2 also called This fieldidentifies the cache line (bits 2-9) T2 100 cacheLine2 is in and thebyte position in the word (bits 0-1). 101- A3 also called This fieldidentifies the cache line (bits 2-9) T3 110 cacheLine3 is in and thebyte position in the word (bits 0-1). 111- A4 also called This fieldidentifies the cache line (bits 2-9) T4 120 cacheLine4 is in and thebyte position in the word (bits 0-1). 121- A5 also called This fieldidentifies the cache line (bits 2-9) T5 130 cacheLine5 is in and thebyte position in the word (bits 0-1). 131- A6 also called This fieldidentifies the cache line (bits 2-9) T6 140 cacheLine6 is in and thebyte position in the word (bits 0-1). 141- A7 also called This fieldidentifies the cache line (bits 2-9) T7 150 cacheLine7 is in and thebyte position in the word (bits 0-1). 151- 10 Interpolation coefficientbetween (T0, T1) and 159 (T2, T3) in 1.8 unsigned fixed point format.160- 11 Interpolation coefficient between (T0, T2) and 168 (T1, T3) in1.8 unsigned fixed point format. 169- 12 Interpolation coefficientbetween (T4, T5) and 177 (T6, T7) in 1.8 unsigned fixed point format.178- 13 Interpolation coefficient between (T4, T6) and 186 (T5, T7) in1.8 unsigned fixed point format. 187- 14 Interpolation coefficientbetween (T0, T1, T2, 195 T3) and (T4, T5, T7, T7) in 1.8 unsigned fixedpoint format. 196 T0BorderColor These bits select which texels are touse the 197 T1BorderColor border color registers (one per bank) instead198 T2BorderColor of the texel from the register file. 199 T3BorderColorT4BorderColor-T7BorderColor are also used 200 T4BorderColor when incombined cache mode to select 201 T5BorderColor between the registerfiles for each texel 202 T6BorderColor 203 T7BorderColor 204- texel Thisfield tells the Dispatch sub unit how many 206 ReadCount0 texel readsthis step needs from Tx Data 0 FIFO and prevents the message being for-warded on if insufficient data has been loaded into the cache from thisFIFO and Tx Data1 FIFO. This is used internally and not passed on to thenext unit. 207- texel This field tells the Dispatch sub unit how many209 ReadCount1 texel reads this step needs from Tx Data 1 FIFO andprevents the message being for- warded on if insufficient data has beenloaded into the cache from this FIFO and Tx Data0 FIFO. This is usedinternally and not passed on to the next unit. 210 texelNeeded0 Thesebits (also called cacheLineValid) are set 211 texelNeeded1 when thecacheLine0 to cacheLine7 fields hold 212 texelNeeded2 valid values andqualify the search operation 213 texelNeeded3 when checking if thereplacement cacheLine 214 texelNeeded4 is in use. 215 texelNeeded5 Theseare used internally and not passed on to 216 texelNeeded6 the next unit.217 texelNeeded7

Primary Cache Manager

The Primary Cache Manager is the interface point for the message streamand is responsible for the loading, readback and context switching ofall the programmable registers in this unit. The registers are notloaded immediately a message is received as outstanding work queued upin the many FIFOs may depend on the current register values. Before theregister is loaded all sub units must be idle (as indicated by all theFIFOs being empty.

The goal of this sub unit is to process a step message in a single cyclewhen all the required texels are in the primary cache or when there isone miss from each bank of the cache. If one bank gets two or moremisses then an extra cycle can be taken to process each miss thatresults in a new texel read. A read may clear multiple misses so theseextra misses don't cost any extra cycles.

The remainder of the sub units can only process one read at a time so ifseveral successive steps cause two misses (one from each bank) theprimary cache manager will eventually stall when the AG0 and AG1 FIFOsbecome full. This is not expected to be a frequent occurrence, exceptmaybe at the start of a new primitive. Multiple cache line loads (in theTexture Filter Unit) will happen sequentially, but the expedited loadingmechanism may allow these to be hidden under earlier step (or other)messages, providing the memory latency is less than the number of queueditems in the M FIFO.

The main component in the Primary Cache Manager is the Cache Directory(one per bank). Block diagrams of this will be given as a significantnumber of gates are involved in these parts. Note these diagrams onlyshow the major data paths and omit clocks, etc.

The overall block diagram is shown in FIG. 11

The cache directory block diagram is shown in FIG. 12. Note thecomplementary key outputs are only used to reduce the cost of thecomparators in the CAM cells.

The CAM Cell block diagram is seen in FIG. 13. The cache directory canonly ever report a maximum of one match per given key.

Address Generator

The Address Generator is presented with one or two texels (via the AG0and AG1 FIFOs) which need to be read. It processes the read requestsserially starting with filter 0 (if present) and calculates the addressof the memory word(s) containing the 2×2 patch of texel data the readtexel is in.

The secondary cache is checked to see if the memory address has alreadybeen read and if not the address, a logical/physical flag and the filternumber is passed over to the Address Mapper and control informationinserted into the T FIFO to load the secondary cache line with the newtexel data and to dispatch the texel data to the Filter Unit.

If the texture map layout is Linear or Patch64 then two or four readswill be necessary to build up the 2×2 patch of texel data the TextureFilter Unit is expecting.

The secondary cache is 4 entries deep and the cache line length matchesthe memory width so is 128 bits. The cache is direct mapped so thesearch and replacement policies are very simple. The cache is mainlyintended to help when the layout is Linear or Patch64, but is alsouseful for bitmask operations (i.e. with spans) and 8 bit indexedtexture maps.

The cache can hold a logical or a physical address so a flag identifiesthe address type to prevent unwanted aliasing from occurring.

The cache line is formed from the least significant bit of j and thefilter bank for all cases except bitmasks (i.e. span operations). Forspan operations the mapping is to take 2 bits out of the i index(adjusted for the texel size) on the assumption that the j index willnormally be zero.

The address calculation follows the normal methods using in theFramebuffer Read Unit and Framebuffer Write Unit with a few smalladditions:

The width of the texture map needs to be reduced as a function of themap level when mip mapping. This width is clamped (as a function oftexel size) for the Patch32_(—)2 and Patch2 layouts to conform to thelayout rules.

The base address for the texture map is taken from one of theTextureBaseAddr registers as a function of map level, map base level andmap max level values held in the corresponding (to the filter)TextureReadMode register.

The Patch32_(—)2 layout will be changed to Patch2 layout when thetexture map width falls below 128 bytes.

Three-D textures have the slice offset (held in TextureMapSize register)factored in to the address calculation.

The borders are added in (if present) separately to the widthcalculation so they don't get divided out due to mip mapping.

Address Mapper

The Address Mappers main job is to map logical addresses to physicaladdresses.

Physical addresses pass straight through with no further processing.

Physical addresses are passed to the Memory Controller via two FIFOs.There is one FIFO per filter bank (the filter bank an addresscorresponds to is passed in the AM FIFO along with the address andlogical flag). The two FIFOs keep the addresses from one texture mapseparate from the addresses from the other texture map. For dualtextures (unlike mip maps) it is not possible to ensure they areallocated into different banks of memory, hence they may try and sharethe same page detector in the Memory Controller. If the two texture mapaddresses are interleaved then we could get the sequence: page break,read texel from map 0, page break, read texel from map 1, etc. This highratio of page breaks is very detrimental to achieving good memoryperformance. By directing the two streams of addresses into their ownFIFOs the Memory Controller is able to group reads from one texture maptogether, thereby amortising the page break costs over more texel reads.

Most of the work in mapping the logical page to a physical page is donein the TLB sub unit and for the majority of mapping requests the TLBwill hold the corresponding physical page so after merging the physicalpage and low order bits of the logical address the physical address ispassed to the Memory Controller.

When the TLB misses, the memory is read (via a separate 64 bit port) tolook up the logical page entry in the Logical Texture Page Table. If thepage is resident the physical address is formed, passed to the MemoryController and the TLB given the logical page and its physical mappingto insert as the most recently accessed page.

When the logical page is not resident the pciHostTexturePage,pciLogicalTexturePage, pciTextureOperation PCI registers are updated forthe faulting page.

If the Download Controller is not currently downloading this logicalpage the pciTextureDownloadRequest bit set, which will inform theTexture DMA Controller (in Gamma for RX, or internal to P3) a transferis needed. (There may be a race condition here where the Address Mapperfails to notice the page just downloaded is the one it wants andrequests it again. This is a safe thing to do, but will waste a smallamount of bandwidth.) The Download Controller will clearpciTextureDownloadRequest at the start of the transfer of this page.

If the Download Controller is currently downloading this logical pagethe pciTextureDownloadRequest bit is not set because the Texture DMAController is already satisfying the request.

The Address Mapper asserts TextureDownloadRequest to theDownloadController and waits for the texture to be downloaded (asindicated by TextureDownloadComplete being asserted), re-reads theLogical Texture Page Table. The physical address is now formed, passedto the Memory Controller and the TLB given the logical page and itsphysical mapping to insert as the most recently accessed page.

This sub unit stalls until the texture page has been downloaded and theLogical Texture Page Table updated. See the Download Controller for adescription of the interface signals between the two sub units.

Communication with the TLB is shown via FIFOs for simplicity and toallow a second source (the Memory Allocator) to invalidate entries inthe TLB. (This may happen asynchronously because, in an RX system, atexture download may be initiated by another RX.)

Translation Look Aside Buffer (TLB)

The TLB responds to two command streams (serviced in round robin order):

The Memory Allocator will request a logical page be invalidated if it ispresent. This will be a comparatively rare operation as it will occuronce per download. In theory the logical page which is being invalidatesshould not be in the TLB as normally there are many more pages in theworking set than TLB entries. Consequently the TLB holds the set of mostrecent pages while the page allocated is the least recently used one andthey should not overlap. (It is possible to make them overlap by settingthe working set to fewer pages than TLB entries or by doing manyexternally initiated texture downloads.)

The Address Mapper checks if the logical to physical page mapping isalready known before it takes the slower route of reading the LogicalTexture Page Table. The TLB is fully associative and can provide thephysical page (if present) in a single cycle (maybe pipelined). Theupdate time can take longer if necessary as this will only occur after aLogical Texture Page Table read.

The TLB holds 16 entries for P3 and 64 entries for RX. The block diagramof the TLB is seen in FIG. 14. The block diagram of an individual CAMcell is shown in FIG. 15.

An alternative arrangement is to hold the physical page as an extensionto the register already holding the logical page and use the matchsignal from a CAM cell to gate the physical page into an or-array. Thiswill be faster, but the storage of the physical page information will beless efficient than in a register file.

The TLB can only ever report a maximum of one match for a given logicalpage

Memory Allocater

The Memory Allocator responds to two command streams (serviced in roundrobin order):

The Download Controller asks for a physical page at the start of a newtexture download. This is passed in the MAC FIFO and the tail page forthe requested memory pool is allocated. The Physical Page AllocationTable is updated (via a private memory port) to move the tail page tothe head of the pool. The previous logical page assigned to theallocated physical page is marked as non resident in the Logical TexturePage Table and invalidated in the TLB. The physical page is returned tothe Download Controller via the MAD FIFO.

The Address Mapper, when there is a TLB miss will ask for the physicalpage the logical page is mapped to be become the most recently used pagein its pool (i.e. it is moved to the head).

Download Controller

The Download Controller waits for the Texture Input FIFO to go not emptyand then reads the first word to find out about the texture which isjust about to be received. It asks the Memory Allocator, via the MACFIFO for a suitable physical page and once it has received this (via theMAD FIFO) it will copy the texture data into the memory. If the logicalpage number of the texture matches up with the one the Address Mapperwas waiting for (shown by the TextureDownloadRequest andpciLogicalTexturePage) the Address Mapper is notified it can continue bythe TextureDownloadComplete signal and TextureDownloadRequest iscleared.

The Download Controller moved 128 bits of data at a time so the downloadbandwidth can cope with AGP 4X systems (the download bandwidth will begreater than 1 GByte per second). This sub unit interacts with theAddress Mapper via the following signals:

Name Width Description pciTextureDown 1 This is asserted by the AddressMapper when loadRequest it hits a page fault and needs a texture pagedownloaded and that page is not currently being downloaded (the downloadwas instigated by another RX). This is cleared by the DownloadController. This signal tells the Texture Download Controller (in Gammafor RX or internal to P3) a download is needed. pciLogical 16 This isset by the Address Mapper to show TexturePage what logical page it isrequesting. TextureDownload 1 This is asserted by the Address Mapperwhen Request it hits a page fault and needs a texture page downloaded.This is cleared by the Download Controller when this page has beendownloaded and the Logical Texture Page Table updated. This signal tellsthe Download Controller the pciLogicalTexturePage register holds a validpage number so it can inform the Address Mapper the download is complete(assuming the page matches). TextureDownload 1 This is asserted by theDownload InProgress Controller and is used to validate theDownloadLogicalPage value. The Address Mapper uses this to check if thedownload it wants is currently being done. DownloadLogical 16 This isset by the Download Page Controller to identify the logical page it isin the process of downloading. TextureDownload 1 This is asserted by theDownload Complete Controller when it has finished downloading thetexture the Address Mapper is waiting on.

Dispatcher

The Dispatcher holds the data part of the secondary cache and forwardstexel data to the primary cache (in the Filter Unit). Texel data isallowed to flow through whenever it arrives from the Memory Controller,but under control from commands received via the T FIFO. A count of thetexel data loaded for each filter bank (i.e. texture map) is maintainedso that an active step message can be delayed until all the texel datait requires is present in the Filter Unit. In normal operation thisdelay should not be invoked very often.

The Dispatcher also handles span processing. This involves zeroextending the texel data to a 64 bit bitmask, byte swapping, mirroringand inverting when necessary and finally anding the pixel mask in thespan step message.

Texture DMA Controller

When a texture page fault occurs the Texture Read Unit interfaces with aTexture DMA Controller to actually get the data. This DMA Controller isin Gamma for a RX based system, or in P3 for a P3 system.

The P3 Texture DMA Controller just handles a single request at a time.The Gamma based Texture DMA Controller is monitoring multiple RXs andbroadcasts the texture data to all RXs and not just the requesting one.

The following hardware signals are used to communicate between theTexture Read Unit and the Texture DMA Controller (each RX will provideits own pair of signals and a mechanism to allow the texture data to bebroadcast to all RXs simultaneously):

pciTextureDownloadRequest. This signal is asserted by Texture Read Unitto request a texture download. It is de-asserted once the texturedownload has started.

TextureFIFOFull. This signal is asserted by the Texture Read Unit whenit is not able to accept any more data being written into theTextureInput FIFO.

When the Texture DMA Controller has detected a download request it readsthree PCI registers from the requester. These registers are:

HostTexturePage. This register holds the host page (in bits 0 . . . 19)where the texture resides. This is either a physical page or a virtualpage. A bit in the TextureOperation register identifies the type ofpage. If the page is a virtual page then an interrupt is generated andthe host will read the page and initiate the DMA once the data has beenmade available. The conversion from page to address is done bymultiplying by 4096.

LogicalTexturePage. This register holds the logical page for the texturedata and is returned back to the Texture Read Unit in bits 0 . . . 15 ofthe first entry written to the Texture Input FIFO (the FIFO is 128 bitswide) as a header preceding the actual texture data. (All 32 bits of theregister are returned in bits 0 . . . 31 to allow for futurecapabilities.) In a multi-RX system all the RXs take the texturedownload and not just the RX which requested it.

TextureOperation. This register holds the following information:

Bit No. Name Description 0-8 Length Transfer length in multiples of 128bit words, maximum being 256 9-10 Memory Pool Identifies which memorypool the physical page is to be allocated from. 11 HostVirtual This bit,when set, indicates the address is a host Address virtual address so thedata cannot be read directly without software intervention. TheTextureDownload interrupt is generated, if enabled.

This data (and bits 12-31) are returned back to the Texture Read Unit inbits 32-64 of the first entry written to the Texture Input FIFO (theFIFO is 128 bits wide) as a header preceding the actual texture data.

Gamma broadcasts the LogialTextureAddress and TextureOperation words tothe TextureInput FIFO before the actual texture data. The Texture ReadUnit on seeing this information will remove any TextureDownloadRequestthis transfer will satisfy and allocate space in its texture working setfor the new texture page.

The three PCI registers need to be offset from their base address basedon the RX number.

If the texture download request results in a TextureDownload interruptbeing generated the TextureAddr PCI register is loaded with the virtualaddress and the TextureOperation PCI register is loaded with theTextureOperation data read from Texture Read Unit before the interruptis generated. The host services the interrupt, reads these two registersand provides the data. When the data is available in memory the physicaladdress where the data is located is written in to the TextureAddr PCIregister. This will wake up the texture download DMA controller and itwill do the download. P3 Texture Downloads behind a Gamma

The P3 DMA controllers would not work behind the initial version of theGamma (geometry processor from 3Dlabs), due to PCI bugs in Gamma. All isnot lost as the texture management can still be done, but now the driver(or interrupt service routine) needs to do more work.

The Texture DMA controller is placed in SlaveTextureDownload mode(controlled by a bit in a PCI register). This will allow the host totake over some of the DMA Controllers functions.

Each logical texture page is marked as being a Virtual Host Page. When apage fault is taken an interrupt will be generated and the host does thefollowing actions:

1. The host will service and clear this interrupt and read theregHostTextureAddr, regLogicalTexturePage and regTextureOperationregisters.

3. The host will write the regLogicalTexturePage into the Texture InputFIFO.

4. The host will write the regTextureOperation into the Texture InputFIFO.

5. The host will write 0 into the Texture Input FIFO (to pad out to 128bits).

6. The host will write 0 into the Texture Input FIFO (to pad out to 128bits).

7. The host will download the texture data to the Texture Input FIFOusing the length field in regTextureOperation to know how much data todownload. The regHostTextureAddr register will indicate what texturepage caused the page fault.

8. Wait until pciTextureDownloadRequest (visible via a PCI statusregister) is low. This will confirm that the data has been downloadedand prevents a possible race condition whereby a false new request isassumed before the old one has been removed.

9. The host will write to the regHostTextureAddr register (any data willdo) and this will tell the Texture DMA Controller that all the texturedata has been transferred.

All FIFO writes must ensure there is enough space for the data to bewritten. The FIFO is 128 bits wide and the data is first buffered in aregister until the 4th word is written at which time all 128 bits arewritten into the FIFO. The FIFO space is measured in 128 bit words.

Texture DMA Controller

void TextureDMAController (void) { // These three registers can also beread and written by the host across // the PCI bus. uint32regHostTextureAddr, regLogicalTexturepage, regTextureOperation; uintl28fifoData; uint9 length; forever { if (pciTextureDownloadRequest isasserted) { // Get the texture request info from the Texture Read Unit.regHostTextureAddr = pciHostTexturePage << 12; regLogicalTexturePage =pciLogicalTexturePage; regTextureOperation = pciTextureOperation; if(textureOperation.VirtualHostAddress) { // Host virtual address. Justraise an interrupt and wait for // the host to kick of the DMA.SetInterrupt (eTextureDownload); // Host responds when it is ready bywriting to the // regHostTextureAddr when it is ready. while (no writeto regHostTextureAddr)   ;    // wait // Now regHostTextureAddr holdsthe physical addr supplied by // host; } // SlaveTextureDownload is abit in a general PCI register. if (SlaveTextureDownload == 0) bits 0 . .. 31 of fifoData = regLogicalTexturePage; bits 32 . . . 63 of fifoData =regTextureOperation; bits 64 . . . 127 of fifoData = 0; WriteTextureFIFO(fifoData); // Wait for the texture request to be removed before sending// texture data. while (pciTextureDownloadRequest is asserted)   ;    //wait. // Transfer the data. length = bits 0 . . . 8 ofregTextureOperation; while (length > 0 &&pciCommandMode.TextureDownloadEnalbe) { bits 0 . . . 31 of fifoData =ReadAddr (regHostTextureAddr + 0); bits 32 . . . 63 of fifoData =ReadAddr (regHostTextureAddr + 4); bits 64 . . . 95 of fifoData =ReadAddr (regHostTextureAddr + 8); bits 96 . . . 127 of fifoData =ReadAddr (regHostTextureAddr + 12); WriteTextureFIFO (fifoData);length--; regHostTextureAddr += 16;        // byte address } } } } }viod WriteTextureFIFO (int128 data) { Wait for room in the Texture InputFIFO; Write data into Texture Input FIFO; } uint32 ReadAddr (uint32byteAddr) { return 32 bits of data read from byteAddr; }

RX Texture DMA Controller

void TextureDMAController (void) { // These three registers can also beread and written by the host across // the PCI bus. uint32regHostTextureAddr, regLogicalTexturePage, regTextureOperation; uint32data; uint9 length; int3 i = 0; int kRXCount;     // Holds the number ofRX in the system forever { if (pciTextureDownloadRequest[i] is asserted){ // Get the texture request info from the Texture Read Unit.regHostTextureAddr = ReadTextureInfo (i, 0) << 12; regLogicalTexturePage= ReadTextureInfo (i, 1); regTextureOperation = ReadTextureInfo (i, 2);if (textureOperation.VirtualHostAddress) // Host virtual address. Justraise an interrupt and wait for // the host to kick of the DMA.SetInterrupt (eTextureDownload); // Host responds when it is ready bywriting to the // regHostTextureAddr when it is ready. while (no writeto regHostTextureAddr)   ;  // wait // Now regHostTextureAddr holds thephysical addr supplied by // host; } bits 0 . . . 31 of fifoData =regLogicalTexturePage; bits 32 . . . 63 of fifoData =regTextureOperation; bits 64 . . . 127 of fifoData = 0; WriteTextureFIFO(fifoData); // Wait for the texture request to be removed before sending// texture data. while (pciTextureDownloadRequest [i] is asserted)  ;  // wait // Transfer the data. length = bits 0 . . . 8 ofregTextureOperation; while (length > 0 &&pciCommandMode.TextureDownloadEnalbe) { fifoData = ReadAddr(regHostTextureAddr + 0) WriteTextureFIFO (aata); fifoData = ReadAddr(regHostTextureAddr + 4) WriteTextureFIFO (aata); fifoData = ReadAddr(regHostTextureAddr + 8); WriteTextureFIFO (aata); fifoData = ReadAddr(regHostTextureAddr + 12); WriteTextureFIFO (aata); length--;regHostTextureAddr += 16;     // byte address } } // Round robbin to thenext RX. i++; if (i == kRXCount)   i = 0; } } uint32 ReadAddr (uint32byteAddr) {   return 32 bits of data read from byteAddr; } // Readingthe TextureFIFO returns the info (saves on address decode and //registers. Note this register is overloaded onto the XXX register. int32ReadRXTextureInfo (int3 rxID, int2 register) { int32 addr, data; addr =pciRXTextureBase + rxID * 12 + register * 4;  // byte addr. data = PCIread on the secondary pci bus to addr; return data; } voidWriteTextureFIFO (int32 data) { int3  1; int32 addr; for (i = 0; i <kRXCount; i++) { while (TextureInputFIFOFull[i] is asserted)    ;  //wait until it goes empty. } // Increment the address to allow PCI bustwrites. addr = pciRXTextureFIFOBase + textureDownloadOffset * 4; Writedata to addr on the secondary PCI bus; textureDownloadOffset++;   //wraps for modulo indexing }

General Control

This unit is controlled by the TextureReadMode0 and TextureReadMode1messages. These have identical fields (although some fields are ignoredin TextureReadMode1). Not all combinations of modes across bothregisters are supported and where there is a clash the modes inTextureReadMode0 take priority. For per pixel mip mapping theTextureRead0 and TextureReadMode1 register should be set up the same asshould the TextureMapWidth0 and TextureMapWidth1 registers.

Bit No Name Description  0 Enable When set causes any texels needed bythe fragment, but not in the primary cache to be read. This is alsoqualified by the TextureEnable bit in the PrepareToRender message. 1-4Width This field holds the width of the map as a power of two. The legalrange of values for this field is 0 (map width = 1) to 11 (map width =2048). This is only used when Texture3D is enabled and then is only usedfor cache management purposes and not for address calculations. Notethis field is ignored in TextureReadMode1. 5-8 Height This field holdsthe height of the map as a power of two. The legal range of values forthis field is 0 (map height = 1) to 11 (map height = 2048). This is onlyused when Texture3D is enabled and then is only used for cachemanagement purposes and not for address calculations. Note field bit isignored in TextureReadMode1.  9-10 TexelSize This field holds the sizeof the texels in the texture map. The options are: 0 = 8 bits 1 = 16bits 2 = 32 bits 3 = 64 bits (Only valid for spans) 11 Texture3D Thisbit, when set, enables 3D texture index generation. Note this bit isignored in TextureReadMode1. The CombinedCache mode bit should not beset when 3D textures are being used. 12 Combine This bit, when set,causes the two banks of the Primary Cache to be joined together, Cachethereby increasing the size of a single texture map which can beefficiently handled. Note this bit is ignored in TextureReadMode1 13-16MapBase This field defines which TextureBaseAddr register should be usedto hold the address for Level map level 0 when mip mapping or thetexture map when not mip mapping. Successive map levels are atincreasing TextureBaseAddr registers upto (and including) theMaxMaxLevel (next field). 3D texrures always use TextureBaseAddr0. 17-20MapMax This field defines the maximum TextureBaseAddr register thistexture should use when mip Level mapping. Any attempt to use beyondthis level will clamp to this level. 21 LogicalTexture This bit, whenset, defines this texture or all mip map levels, if mip mapping, to belogically mapped so undergo logical to physical translation of thetexture addresses. 22 Origin This field selects where the origin is fora texture map with a Linear or Patch64 layout. The options are: 0 = TopLeft. 1 = Bottom Left A Patch32_2 or Patch2 texture map is always bottomleft origin. 23-24 Texture This field defines any special processingneeded on the texel data before it can be used. Type The options are: 0= Normal. 1 = Eight bit indexed texture. 2 = Sixteen bit YVYU texture in422 format. 3 = Sixteen bit VYUY texture in 422 format. 25-27 ByteSwapThis field defines the byte swapping, if any, to be done on texel datawhen it is used as a bitmap. This is automatically done when spans areused. Bit 27, when set, causes adjacent bytes to be swapped, bit 26adjacent 16 bit words to be swapped and bit 27 adjacent 32 bit words tobe swapped. In combination this byte swap the input (ABCDEFGH) asfollows: 0 ABCDEFGH 1 BADCFEHG 2 CDABGHEF 3 ABCDEFGH 4 EFGHABCD 5FEHGBADC 6 GHEFCDAB 7 HGFEDCBA 28 Mirror This bit, when set will mirrorany bitmap data. This only works for spans. 29 Invert This bit, when setwill invert any bitmap data. This only works for spans. 30 Opaque Thisbit, when set, will cause the SpanColorMask to be modified rather thanthe pixel mask Span in SpanStepX or SpanStepYDom messages.

The TextureCacheReplacementMode register controls the replacement policyin the primary cache. It has the following fields:

Bit No Name Description  0 Keep This bit, when set, will keep the oldesttexels on the scanline when the cache bank 0 is about to Oldest0 wrapand just re-use a set of scratch Iines. 1-5 Scratch This field holds thenumber of cache lines to use as scratch lines when the cache bank 0wraps Lines0 and the KeepOldest mode bit is set. The value in this fieldhas a MIN_SCRATCH_SIZE value (currently 8) added to it so we canguarantee the scratch line size can always accommodate the cache linesthe current fragments requires with some left over. Failure to make thisprovision would lead to deadlock. 6 Keep This bit, when set, will keepthe oldest texels on the scanline when the cache bank 1 is about toOldest1 wrap and just re-use a set of scratch lines.  7-11 Scratch Thisfield holds the number of cache lines to use as scratch lines when thecache bank 1 wraps Lines1 and the KeepOldest mode bit is set. The valuein this field has a MIN_SCRATCH_SIZE value (currently 8) added to it sowe can guarantee the scratch line size can always accommodate the cachelines the current fragments requires with some left over. Failure tomake this provision would lead to deadlock. 12 Show This bit, when set,will cause the fragments color to be replaced by information relating tothe CachInfo cachep3 s performance. The red component shows the numberof texture 0 cache line misses The green component shows the number oftexture 1 cache line misses. The coding is as follows: 0×40 = 0 misses0×80 = 1 miss 0×A0 = 2 misses 0×C0 = 3 misses 0×E0 = 4 misses The bluecomponent holds the number of cycles * 8 the fragment was delayedwaiting for texel data. The alpha component holds the number of cycles *8 the primary cache was stalled waiting for a free cache line.

Sample Computer System Embodiment

FIG. 1 shows a computer incorporating an embodiment of the innovativegraphics innovations in a video display adapter 445. The completecomputer system includes in this example: user input devices (e.g.keyboard 435 and mouse 440); at least one microprocessor 425 which isoperatively connected to receive inputs from the input devices, acrosse.g. a system bus 431, through an interface manager chip 430 whichprovides an interface to the various ports and registers; themicroprocessor interfaces to the system bus through perhaps a bridgecontroller 427; a memory (e.g. flash or non-volatile memory 455, RAM460, and BIOS 453), which is accessible by the microprocessor; a dataoutput device (e.g. display 450 and video display adapter card 445)which is connected to output data generated by the microprocessor 425;and a mass storage disk drive 470 which is read-write accessible,through an interface unit 465, by the microprocessor 425.

Optionally, of course, many other components can be included, and thisconfiguration is not definitive by any means. For example, the computermay also include a CD-ROM drive 480 and floppy disk drive (“FDD”) 475which may interface to the disk interface controller 465. Additionally,L2 cache 485 may be added to speed data access from the disk drives tothe microprocessor 425, and a PCMCIA 490 slot accommodates peripheralenhancements. The computer may also accommodate an audio system formultimedia capability comprising a sound card 476 and a speaker(s) 477.

The following background publications provide additional detailregarding details of computer system implementations of the disclosedembodiments, and of modifications and variations thereof. All of thesepublications are hereby incorporated by reference: Tom Shanley, PentiumPro Processor System Architecture, Mindshare (1997); James Foley, etalii, Computer Graphics Principles and Practice, Addison-Wesley (1996);Richard Ferraro, Programmer's Guide to the EGA and VGA Cards,Addison-Wesley (1990); Clive Maxfield and Alvin Brown, Bebop Bytes Back,Doone Publications (1997); Pentium II XEON Processor, Intel Corp.(1998); Intel Architecture Software Developer's Manual vols. 1-3, IntelCorp. (1998); P6 Family of Processors Hardware Development Manual, IntelCorp. (1998); AGP Design Guide, Intel Corp. (1998); AGP ProSpecification, Intel Corp. (1998); Jim Chu and Frank Hady, MaximizingAGP Performance, Intel Corp. (1998).

FIG. 16 shows a sample configuration where two rasterizers are served bya common memory manager and bus interface chip. In the example shown,both chips have a PCI bus connection to the CPUs as well as anarbitrated connection to memory, but of course many other configurationsare also possible.

Modifications and Variations

As will be recognized by those skilled in the art, the innovativeconcepts described in the present application can be modified and variedover a tremendous range of applications, and accordingly the scope ofpatented subject matter is not limited by any of the specific exemplaryteachings given.

Note that other levels of memory could be added, e.g. integrated DRAM,or L2 SRAM.

Optionally the user could be given a memory allocation option.

For another example, the virtual texture innovations disclosed in thepresent application can optionally be used in combination with at leastsome of the previous virtual texture schemes discussed above.

The following background publications provide additional detailregarding possible implementations of the disclosed embodiments, and ofmodifications and variations thereof, and the predictable results ofsuch modifications: Advances in Computer Graphics (ed. Enderle 1990);Chellappa and Sawchuk, Digital Image Processing and Analysis (1985);Computer Graphics Hardware (ed. Reghbati and Lee 1988); ComputerGraphics: Image Synthesis (ed. Joy et al.); Foley et al., Fundamentalsof Interactive Computer Graphics (2.ed. 1984); Foley, Computer GraphicsPrinciples & Practice (2.ed. 1990); Foley, Introduction to ComputerGraphics (1994); Hearn and Baker, Computer Graphics (2.ed. 1994); Hill,Computer Graphics (1990); Latham, Dictionary of Computer Graphics(1991); Magnenat-Thalma, Image Synthesis. Theory & Practice (1988);Prosise, How Computer Graphics Work (1994); Rimmer, Bit Mapped Graphics(2.ed. 1993); Salmon, Computer Graphics Systems & Concepts (1987);Schachter, Computer Image Generation (1990); Watt, Three-DimensionalComputer Graphics (2.ed. 1994, 3.ed. 2000); Scott Whitman,Multiprocessor Methods For Computer Graphics Rendering; David S. Ebertet al., Texturing and Modeling; Tomas Moller and Eric Haines, Real-TimeRendering; Michael O'Rourke, Principles of Three-Dimensional ComputerAnimation; Blinn, Jim Blinn's Comer: Dirty Pixels; Blinn, Jim Blinn'sCorner: A Trip Down the Graphics Pipeline; Watt and Watt, AdvancedAnimation and Rendering Techniques: Theory and Practice; the SIGGRAPHProceedings for the years 1980-to date; and the IEEE Computer Graphicsand Applications magazine for the years 1990-to date; all of which arehereby incorporated by reference.

None of the description in the present application should be read asimplying that any particular element, step, or function is an essentialelement which must be included in the claim scope: THE SCOPE OF PATENTEDSUBJECT MATTER IS DEFINED ONLY BY THE ALLOWED CLAIMS. Moreover, none ofthese claims are intended to invoke paragraph six of 35 USC section 112unless the exact words “means for” are followed by a participle.

What is claimed is:
 1. A computer system, comprising: at least onecentral processing unit; at least one main memory which is read/writeaccessible by said central processing unit; at least one bulk storageunit which is read/write accessible by said central processing unit, andwhich has a minimum access time, as seen by said central processingunit, which is more than ten times greater than the minimum access timeof said main memory; specialized graphics-processing logic, whichperforms rendering functions on graphics data generated by said centralprocessing unit; and specialized graphics memory which is used by saidgraphics-processing logic as primary memory, but is not used by saidcentral processing unit as part of said main memory; wherein said mainmemory is configured to provide a first level of virtualizing for saidgraphics memory, and said bulk storage is configured to provide a secondlevel of virtualizing for said graphics memory.
 2. The system of claim1, wherein said specialized graphics-processing logic comprises anon-chip cache memory.
 3. A computer system, comprising: at least onemain memory; at least one bulk storage unit; specialzedgraphics-processing logic, which performs rendering functions ongraphics data; dedicated graphics memory which is used by saidgraphics-processing logic as primary memory; first memory managementlogic which virtualizes said graphics memory into a first portion ofsaid main memory; and second memory management logic which virtualizessaid main memory, including said first portion thereof, into said bulkstorage unit.
 4. The system of claim 3, wherein said bulk storage unitis a hard disk drive.
 5. The system of claim 3, wherein said firstmemory management logic can lock down portions of said main memory, andwherein said second memory management logic cannot page out portions ofsaid main memory which are being locked down by said first memorymanagement logic.
 6. The system of claim 5, wherein said first memorymanagement logic can never lock down as much as half of said mainmemory.
 7. The system of claim 5, wherein said specializedgraphics-processing logic comprises an on-chip cache memory.
 8. Thesystem of claim 3, wherein said first memory management unit, but notsaid second memory management unit, is located on a card with saidgraphics-processing logic.
 9. The system of claim 3, wherein saidspecialized graphics-processing logic comprises an on-chip cache memory.10. A method of performing three-dimensional graphics processing,comprising the steps of: performing graphics rendering operations whichare stored on a chip and which act on a set of pixels; accessing texturedata needed by said rendering operations, using a first data storageunit which is on said chip and second and third data storage units whichare part of a host computer, but not part of said chip; wherein saidthird data storage unit is slower than said second data storage unit;and wherein memory accesses by said chip are both virtualized into saidsecond memory and also secondarily virtualized into said third memory.